I just installed matplotlib in Ubuntu 9.10 using the synaptic package system. However, when I try the following simple example
>>> from pylab import plot;
>>> plot([1,2,3],[1,2,3])
[<matplotlib.lines.Line2D object at 0x9aa78ec>]
I get no plot window. Any ideas on how to get the plot window to show?
pylab.show()
works but blocks (you need to close the window).A much more convenient solution is to do
pylab.ion()
(interactive mode on) when you start: all (the pylab equivalents of)pyplot.*
commands display their plot immediately. More information on the interactive mode can be found on the official web site.I also second using the even more convenient
ipython -pylab
(--pylab
, in newer versions), which allows you to skip thefrom … import …
part (%pylab
works, too, in newer IPython versions).If you are starting IPython with the
--pylab
option, you shouldn't need to callshow()
ordraw()
. Try this:Try this:
BEFORE import pylab
Any errors show up? This might an issue of not having set the backend. You can set it from the Python interpreter or from a config file (
.matplotlib/matplotlibrc
) in you home directory.To set the backend in code you can do
where 'Agg' is the name of the backend. Which backends are present depend on your installation and OS.
http://matplotlib.sourceforge.net/faq/installing_faq.html#backends
http://matplotlib.org/users/customizing.html
Modern IPython uses the "
--matplotlib
" argument with an optional backend parameter. It defaults to "auto", which is usually good enough on Mac and Windows. I haven't tested it on Ubuntu or any other Linux distribution, but I would expect it to work.You can type
or better, use
ipython -pylab
.