I’m using Python 2.7.3 in 64-bit. I installed pandas as well as matplotlib 1.1.1, both for 64-bit. Right now, none of my plots are showing. After attempting to plot from several different dataframes, I gave up in frustration and tried the following first example from http://pandas.pydata.org/pandas-docs/dev/visualization.html:
import matplotlib.pyplot as plt ts = Series(randn(1000), index=date_range ('1/1/2000', periods=1000)) ts = ts.cumsum() ts.plot() pylab.show()
And no plot window appeared. Other StackOverflow threads I’ve read suggested I might be missing DLLs. Any suggestions?
I’m not convinced this is a pandas issue at all.
import matplotlib.pyplot as plt plt.plot(range(10)) plt.show()
bring up a plot?
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.
I had this problem when working from within a virtualenv.
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
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.
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__'
Try installing these libraries, it works for me:
$ sudo apt-get install tcl-dev tk-dev python-tk python3-tk