Ask Your Question
0

display matplotlib graphic in Sage cell server

asked 2012-08-30 00:34:11 +0100

calc314 gravatar image

updated 2015-01-13 18:02:15 +0100

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 10:26:34 +0100 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2012-08-31 13:46:38 +0100

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 16:26:51 +0100 )edit
0

answered 2012-08-30 10:36:35 +0100

kcrisman gravatar image

updated 2012-08-30 10:37:55 +0100

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 10:40:56 +0100 )edit

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

kcrisman gravatar imagekcrisman ( 2012-08-30 12:10:25 +0100 )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-30 00:34:11 +0100

Seen: 1,165 times

Last updated: Aug 31 '12