Ask Your Question

no more inline matplotlib plots in sage notebook

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

sbott gravatar image


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.plot(x, np.sin(x), label='sin(x)')  

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



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/", 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/", line 363, in savefig
    return fig.savefig(*args, **kwargs)
  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/", line 1084, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/", line 1853, in print_figure
    print_method = self._get_print_method(format)
  File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/", 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


edit retag flag offensive close merge delete


Hi - do the instructions at (search for "pylab") work?

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

1 Answer

Sort by ยป oldest newest most voted

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

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


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 +0200 )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


Asked: 2012-01-05 05:23:41 +0200

Seen: 1,309 times

Last updated: Jan 05 '12