Matplotlib绘图结果为空白尽管数据有值

我是数据分析、Python和机器学习的新手,目前正在研究时间序列预测。使用以下代码,我能够获取训练和测试数据的值,但绘制出来的图表却是空白的。

import pandas as pd import numpy as np import matplotlib.pyplot as pltimport statsmodels.tsa.api as ExponentialSmoothing#Importing datadf = pd.read_csv('international-airline-passengers - Copy.csv')#Printing headprint(df.head())#Printing tailprint(df.tail())df = pd.read_csv('international-airline-passengers - Copy.csv', nrows = 11856)#Creating train and test set #Index 10392 marks the end of October 2013 train=df[0:20]test=df[20:]#Aggregating the dataset at daily leveldf.Timestamp = pd.to_datetime(df.Month,format='%m/%d/%Y %H:%M') df.index = df.Timestamp df = df.resample('D').mean()train.Timestamp = pd.to_datetime(train.Month,format='%m/%d/%Y %H:%M')print('1')print(train.Timestamp)train.index = train.Timestamp train = train.resample('D').mean() test.Timestamp = pd.to_datetime(test.Month,format='%m/%d/%Y %H:%M') test.index = test.Timestamp test = test.resample('D').mean()train.Count.plot(figsize=(15,8), title= 'Result', fontsize=14)test.Count.plot(figsize=(15,8), title= 'Result', fontsize=14)plt.show()

即使训练和测试数据有值,我还是不明白为什么图表会显示为空白。提前感谢您的帮助。


回答:

我想我找到了问题所在。你在这里使用了train.Count.plot,而“plt”的值仍然是空的。如果你查阅matplotlib的文档(链接如下),你会发现你需要先在plt中存储一些值,因为这里plt是空的,所以它返回了一个空图。你实际上并没有绘制任何东西,只是显示了一个空白图表。

例如:plt.subplots(values) 或 plt.scatter(values),或者根据需求使用它的任何其他函数。希望这对你有帮助。

https://matplotlib.org/

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中创建了一个多类分类项目。该项目可以对…

发表回复

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