25

I am using the anaconda distribution of ipython/Qt console. I want to plot things inline so I type the following from the ipython console:

%pylab inline

Next I type the tutorial at (http://pandas.pydata.org/pandas-docs/dev/visualization.html) into ipython...

import matplotlib.pyplot as plt
import pandas as pd 
ts = pd.Series(randn(1000), index = pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()

... and this is all that i get back:

<matplotlib.axes.AxesSubplot at 0x109253410>

But there is no plot. What could be wrong? Is there another command that I need to supply? The tutorial suggests that that is all that I need to type.

4

2 回答 2

32

在您运行之前不会显示图

plt.show()

于 2014-03-27T02:40:58.297 回答
9

可能有两种方法可以解决这个问题:

1) 调用 inline/osx/qt/gtk/gtk3/tk 后端。取决于您一直在使用的 ipython 控制台。因此,只需执行以下操作:

%matplotlib inline#这里调用了内联后端,这消除了在每次绘图后调用 show 的必要性。

或者对于 ipython/qt 控制台,执行:

%matplotlib qt#这个对我有用,因此,取决于你使用的 ipython 控制台。

#

2)或者,按照前面提到的传统方式已经在本页上面回答):

plt.show() #但是,您每次都必须调用此显示函数。

于 2016-08-01T02:59:27.070 回答