Ask Your Question
1

no more inline matplotlib plots in sage notebook

asked 2012-01-05 05:23:41 +0100

sbott gravatar image

Hi,

I can't get any matplotplib/pylab plots inline in a notebook. Plots now are created as pdf files that open in another window.

For example, the code below used to create the plot in a new box after the instruction plt.savefig('.')

import numpy as np
import pylab as plt
x = np.arange(-2 * np.pi, 2 * np.pi,0.1) 
plt.figure(1)  
plt.clf() 
plt.plot(x, np.sin(x), label='sin(x)')  
plt.savefig('.')

now it returns a link '.pdf' to a pdf file.

Using

plt.savefig('a.png')

returns the following traceback:

Traceback (most recent call last):    
  File "", line 1, in <module>

  File "/private/var/folders/k7/k7XHz3-82RazCk+kNOj55U+++TM/-Tmp-/tmpjD4zHK/___code___.py", line 14, in <module>
    exec compile(u"plt.savefig('a.png')" + '\n', '', 'single')
  File "", line 1, in <module>

  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/pyplot.py", line 363, in savefig
    return fig.savefig(*args, **kwargs)
  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/figure.py", line 1084, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1853, in print_figure
    print_method = self._get_print_method(format)
  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1793, in _get_print_method
    '%s.' % (format, ', '.join(formats)))
ValueError: Format "png" is not supported.
Supported formats: pdf.

I don't know what settings changes I may have done, and couldn't find any documented help format settings in sage for matplotlib plots. Interestingly I used to experience before the impossibility to export sage generated plots in pdf... It would be nice to have a better control on these settings.

Thank you for any help

Samuel

edit retag flag offensive close merge delete

Comments

Hi - do the instructions at http://doc.sagemath.org/html/en/refer... (search for "pylab") work?

kcrisman gravatar imagekcrisman ( 2017-06-08 19:04:10 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-01-05 15:48:09 +0100

Shashank gravatar image

I am not sure but, I think you need imagemagick to save plots as png files. Do you have it installed on the computer? Can you see whether installing imagemagick on the computer solves the problem?

edit flag offensive delete link more

Comments

Thanks for the comment but I don't believe this is related with imagemagick. On other computers sage installations (same version 4.6.2 and no imagemagick) I never experienced trouble with inline plots in the notebook. savefig('.') savefig('name') savefig('name.png') all generated a graph in png format displayed in the notebook browser. I'm not aware of any settings change on my main computer, but now savefig('.') savefig('name') generate a link which opens the graph as pdf in a new window. Sincerely

sbott gravatar imagesbott ( 2012-01-05 17:57:40 +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-01-05 05:23:41 +0100

Seen: 1,397 times

Last updated: Jan 05 '12