Pandas.plotting 不显示图表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47560074/
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-14 04:50:29  来源:igfitidea点击:

Pandas.plotting doesn't show graph

pythonpandasmatplotlibmachine-learning

提问by michele

I'm following the tutorial in the book "introduction to machine learning with python" and i've copied the following code:

我正在学习“python机器学习简介”一书中的教程,我复制了以下代码:

#create dataframe from data in X_train
#label the colums using the strings in iris_dataset.features_names
iris_dataframe = pd.DataFrame(X_train, columns = iris_dataset.feature_names)
#create a scatter matrix from the dataframe, color by y_train
pd.plotting.scatter_matrix(iris_dataframe,c=y_train,
                           figsize=(15,15), marker='o', 
                           hist_kwds={'bins':20},s=60, 
                           alpha=.8,
                           cmap=mglearn.cm3)

It should plot a graph,but it only print those lines:

它应该绘制一个图形,但它只打印这些行:

array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f0d073934a8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07352908>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07376e48>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d0732ee48>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7f0d072e3f28>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d072e3f60>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07308ac8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07211400>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7f0d071ca470>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07183470>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d071be470>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07165e80>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07127390>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d070e5390>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d0709d390>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f0d07047da0>]], dtype=object)

Can someone tell me a reason?

有人能告诉我原因吗?

EDIT-SOLVED:I do not know why but a after a re-run of the cells, the graph apperead..

编辑解决:我不知道为什么,但是在重新运行单元格后,图表出现了..

回答by ListsAndThings

pandas does not have a plotting library in itself. most users normally utilize the matplotlib library when plotting which has a different set of commands. Assuming you have all of the correct libraries installed including matplotlib I would end your code with:

pandas 本身没有绘图库。大多数用户在绘图时通常使用 matplotlib 库,该库具有不同的命令集。假设您安装了所有正确的库,包括 matplotlib,我会用以下代码结束您的代码:

import matplotlib.pyplot as plt
#assuming you got the correct conversion to a pandas dataframe  
pd.plotting.scatter_matrix(df,c=y_train,
                       figsize=(15,15), marker='o', 
                       hist_kwds={'bins':20},s=60, 
                       alpha=.8,
                       cmap=mglearn.cm3)


plt.show()

Here is a linkto the matplotlib library that goes into the plt.show() There is also methods to save the figure, which can be found in the documentation here

这是进入 plt.show() 的 matplotlib 库的链接还有保存图形的方法,可以在此处的文档中找到

回答by michele

SOLVED! I do not know why but after a re-run of all the cells of the jupyter notebook, the graph apperead correctly.

解决了!我不知道为什么,但在重新运行 jupyter notebook 的所有单元格后,图形显示正确。