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:
INPUT:
import matplotlib.pyplot as plt
ts = Series(randn(1000), index=date_range ('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
pylab.show()
OUTPUT:
Axes(0.125,0.1;0.775x0.8)
And no plot window appeared. Other StackOverflow threads I've read suggested I might be missing DLLs. Any suggestions?
It means if we are not using the show() function, it wouldn't show any plot. When we use the show() function in the non-interactive mode. That means when we write the code in the file it will show all the figures or plots and blocks until the plots have been closed.
Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib: Delete the caches from your Matplotlib configuration directory. Delete any Matplotlib directories or eggs from your installation directory.
Avoid Display With ioff() Method We can turn the interactive mode off using matplotlib. pyplot. ioff() methods. This prevents figure from being displayed.
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,
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 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.
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__'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With