Ask Your Question
0

display matplotlib graphic in Sage cell server

asked 12 years ago

calc314 gravatar image

updated 10 years ago

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')
Preview: (hide)

Comments

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

kcrisman gravatar imagekcrisman ( 12 years ago )

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

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'})
Preview: (hide)
link

Comments

Thanks for the help!

calc314 gravatar imagecalc314 ( 12 years ago )
0

answered 12 years ago

kcrisman gravatar image

updated 12 years ago

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...

Preview: (hide)
link

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 ( 12 years ago )

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

kcrisman gravatar imagekcrisman ( 12 years ago )

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: 12 years ago

Seen: 1,183 times

Last updated: Aug 31 '12