Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

python - matplotlib plot window won't appear

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...