Pandas.plotting不显示图表

我正在按照《Python机器学习导论》这本书中的教程进行学习,并且我已经复制了以下代码:

#create dataframe from data in X_train#label the colums using the strings in iris_dataset.features_namesiris_dataframe = pd.DataFrame(X_train, columns = iris_dataset.feature_names)#create a scatter matrix from the dataframe, color by y_trainpd.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)

有人能告诉我原因吗?

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


回答:

pandas本身没有绘图库。大多数用户在绘图时通常使用matplotlib库,后者有一套不同的命令。假设你已经安装了包括matplotlib在内的所有正确库,我建议在你的代码末尾加上以下内容:

import matplotlib.pyplot as plt#假设你已经正确地将数据转换为pandas数据框架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()

这是指向matplotlib库中plt.show()链接。此外,还有保存图形的方法,可以在文档中找到,这里有说明

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注