gpt4 book ai didi

python - Pandas.plotting 不显示图形

转载 作者:行者123 更新时间:2023-11-28 21:38:53 24 4
gpt4 key购买 nike

我正在按照“使用 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)

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

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)

有人能告诉我原因吗?

EDIT-SOLVED:我不知道为什么,但在重新运行单元格后,图表出现了......

最佳答案

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()

这是一个link进入 plt.show() 的 matplotlib 库还有保存图形的方法,可以在文档中找到 here

关于python - Pandas.plotting 不显示图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47560074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com