pandas ipython 熊猫图不显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18388870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:06:13  来源:igfitidea点击:

ipython pandas plot does not show

pythonmatplotlibpandasipythonanaconda

提问by cantdutchthis

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:

我正在使用 ipython/Qt 控制台的 anaconda 发行版。我想内联绘制内容,所以我从 ipython 控制台输入以下内容:

%pylab inline

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

接下来,我将 ( http://pandas.pydata.org/pandas-docs/dev/visualization.html) 上的教程输入 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.

但是没有情节。可能有什么问题?我需要提供另一个命令吗?该教程表明这就是我需要输入的全部内容。

回答by user792036

Plots are not displayed until you run

在您运行之前不会显示图

plt.show()

plt.show()

回答by Surya

There could be 2 ways to approach this problem:

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

1) Either invoke the inline/osx/qt/gtk/gtk3/tk backend. Depends on the ipython console that you have been using. So, simply do:

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

%matplotlib inline#Here the inline backend is invoked, which removes the necessity of calling show after each plot.

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

or for ipython/qt console, do:

或者对于 ipython/qt 控制台,请执行以下操作:

%matplotlib qt#This one works for me, thus, depends on the ipython console you use.

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

#

#

2) Or, do the traditional way as aforementioned(already answered above on this page):

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

plt.show()#However, you will have to call this show function each time.

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