ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 31 Aug 2012 09:26:51 -0500display matplotlib graphic in Sage cell serverhttps://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/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')
Wed, 29 Aug 2012 17:34:11 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/Comment by kcrisman for <p>I'm writing a histogram interact in the Sage cell server at <a href="http://aleph.sagemath.org">aleph.sagemath.org</a>, 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?</p>
<pre><code>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')
</code></pre>
https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19146#post-id-19146It seems like the problem is 5.2, not 5.0... I'll look at this a little now.Thu, 30 Aug 2012 03:26:34 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19146#post-id-19146Answer by Jason Grout for <p>I'm writing a histogram interact in the Sage cell server at <a href="http://aleph.sagemath.org">aleph.sagemath.org</a>, 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?</p>
<pre><code>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')
</code></pre>
https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?answer=13981#post-id-13981At 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'})
Fri, 31 Aug 2012 06:46:38 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?answer=13981#post-id-13981Comment by calc314 for <p>At the end, put either the following, which will be supported in the future:</p>
<pre><code>plt.savefig('test2.png')
html("<img src='cell://test2.png' />")
</code></pre>
<p>or put the following, which uses internal things that might change in the future:</p>
<pre><code>plt.savefig('test2.png')
sys._sage_.display_message({'text/plain': 'an image', 'text/image-filename': 'test2.png'})
</code></pre>
https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19131#post-id-19131Thanks for the help!Fri, 31 Aug 2012 09:26:51 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19131#post-id-19131Answer by kcrisman for <p>I'm writing a histogram interact in the Sage cell server at <a href="http://aleph.sagemath.org">aleph.sagemath.org</a>, 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?</p>
<pre><code>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')
</code></pre>
https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?answer=13971#post-id-13971Try
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...Thu, 30 Aug 2012 03:36:35 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?answer=13971#post-id-13971Comment by calc314 for <p>Try </p>
<pre><code> plt.savefig('test2.png')
</code></pre>
<p>instead. That seems to solve the problem for me; at least, a link appears for the figure. <code>SAGE_TMP</code> 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...</p>
https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19145#post-id-19145Yes. 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.Thu, 30 Aug 2012 03:40:56 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19145#post-id-19145Comment by kcrisman for <p>Try </p>
<pre><code> plt.savefig('test2.png')
</code></pre>
<p>instead. That seems to solve the problem for me; at least, a link appears for the figure. <code>SAGE_TMP</code> 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...</p>
https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19144#post-id-19144Since the Sage cell server has a different structure than the notebook, I don't know. Sorry :(Thu, 30 Aug 2012 05:10:25 -0500https://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/?comment=19144#post-id-19144