views:

455

answers:

3

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?

+1  A: 

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.

http://matplotlib.sourceforge.net/faq/installing_faq.html#backends

Matti
+4  A: 

You can type

import pylab
pylab.show()

or better, use ipython -pylab.

Peter
A: 

Since pylab.show blocks (you need to close the window), you might want to do pylab.draw() instead, which gives you back the Python shell prompt.

More generally, you might want to try ion() (interactive mode on) when you start: as far as I understand, this automatically performs draw() for you, when you plot.

I also second using ipython -pylab, which allows you to skip the from … import … part.

EOL
but you need to call `pylab.show()` first to even open a figure.
Steve
@Steve: my experience is that this strongly depends on the backend. On Mac OS X with the regular Python shell, I don't have to do show() (or draw(), for that matter): plot() opens a new window.
EOL
Ah, okay. Good point. I only have experience with ipython in Linux.
Steve