matplotlib plot window won't appear

Solution 1:

I'm not convinced this is a pandas issue at all.

Does

import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()

bring up a plot?

If not:

How did you install matplotlib? Was it from source or did you install it from a package manager/pre-built binary?

I suspect that if you run:

import matplotlib            
print matplotlib.rcParams['backend']

The result will be a non-GUI backend (almost certainly "Agg"). This suggests you don't have a suitable GUI toolkit available (I personally use Tkinter which means my backend is reported as "TkAgg").

The solution to this depends on your operating system, but if you can install a GUI library (one of Tkinter, GTK, QT4, PySide, Wx) then pyplot.show() should hopefully pop up a window for you.

HTH,

Solution 2:

I had this problem when working from within a virtualenv.

Cause

The cause of the problem is that when you pip install matplotlib, it fails to find any backends (even if they are installed on your machine), so it uses the "agg" backend, which does not make any plots, just writes files. To confirm that this is the case, go: python -c "import matplotlib; print matplotlib.get_backend()", you probably see agg.

I could however, successfully use matplotlib on the system (outside the virtualenv). I also failed to install PySide, PyQt, or get it to work for TkAgg, for various different reasons.

Solution

I eventually just made a link to my system version of matplotlib (starting from outside the venv):

...$ pip install matplotlib
...$ cd /to/my/venv/directory
...$ source venv/bin/activate
(venv) .... $ pip uninstall matplotlib
(venv) .... $ ln -s /usr/lib/pymodules/python2.7/matplotlib $VIRTUAL_ENV/lib.python*/site-packages

After that, I could use matplotlib and the plots would show. Your local version of matplotlib may be in a different place. To see where it is, go (outside of the venv, in python)

...$ python -c 'import matplotlib; matplotlib.__file__'