Ask Your Question
0

display matplotlib graphic in Sage cell server

asked 2012-08-29 17:34:11 -0500

calc314 gravatar image

updated 2015-01-13 11:02:15 -0500

FrédéricC gravatar image

I'm writing a histogram interact in the Sage cell server at aleph.sagemath.org, and I can't get the graphic to display. The graphics display nicely within the interact in Sage 5.0 on my local installation, but won't appear in Sage 5.2 on the cell server. What can I do to display the graphic?

import matplotlib.pyplot as plt
@interact
def doit(title='Title',xlabel=('horizontal axis label','xlabel'),ylabel=('vertical axis label','ylabel'),numbins=slider(1,100,1,8,'number of bins'),data=input_box([358,311,172,190,369,298,308,330,223,187,371,419,296,298,258])):
    plt.figure()
    hp=plt.hist(data,bins=numbins)
    plt.title(title)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.savefig(SAGE_TMP+'test2.png')
edit retag flag offensive close merge delete

Comments

It seems like the problem is 5.2, not 5.0... I'll look at this a little now.

kcrisman gravatar imagekcrisman ( 2012-08-30 03:26:34 -0500 )edit

2 answers

Sort by » oldest newest most voted
2

answered 2012-08-31 06:46:38 -0500

Jason Grout gravatar image

At the end, put either the following, which will be supported in the future:

plt.savefig('test2.png')
html("<img src='cell://test2.png' />")

or put the following, which uses internal things that might change in the future:

plt.savefig('test2.png')
sys._sage_.display_message({'text/plain': 'an image', 'text/image-filename': 'test2.png'})
edit flag offensive delete link more

Comments

Thanks for the help!

calc314 gravatar imagecalc314 ( 2012-08-31 09:26:51 -0500 )edit
0

answered 2012-08-30 03:36:35 -0500

kcrisman gravatar image

updated 2012-08-30 03:37:55 -0500

Try

    plt.savefig('test2.png')

instead. That seems to solve the problem for me; at least, a link appears for the figure. SAGE_TMP is really only for use in testing, and has nothing to do with any notebook cells. That it worked before is really a bug, I would think...

edit flag offensive delete link more

Comments

Yes. I tried that prior to trying SAGE_TMP. I get the link, but I want to see the graphic appear. Is there a way to make the graphic appear? I tried a few things using the Image package put to no avail.

calc314 gravatar imagecalc314 ( 2012-08-30 03:40:56 -0500 )edit

Since the Sage cell server has a different structure than the notebook, I don't know. Sorry :(

kcrisman gravatar imagekcrisman ( 2012-08-30 05:10:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-08-29 17:34:11 -0500

Seen: 770 times

Last updated: Aug 31 '12