我有一个大的csv文件,里面有3个月的温度数据。第1列是月,第2列是日,第3列是小时,第4列是分钟,第5列是温度。我试图用x轴上列出的日期/月份来绘制所有3个月的温度数据。以下是我目前所掌握的情况:
filename ='TemperatureFile.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
month, day, hour, temperature = [], [], [], []
for row in reader:
mon=datetime.strptime(row[0],"%m")
month.append(mon)
date=datetime.strptime(row[1],"%d")
day.append(date)
hourx=datetime.strptime(row[2],"%H:%M")
hour.append(hourx)
temp = float(row[3])
temperature.append(temp)
datefinal=date.isoformat(month, day)
#date.isoformat(months, days).isoformat()==
fig = plt.figure(dpi=128, figsize=(10,6))
plt.plot(datefinal,temperature, c='red')
plt.title("Temperatures", fontsize=20)
plt.xlabel('Date', fontsize=16)
plt.ylabel('Temperatures(F)', fontsize=16)
plt.show()
我不知道如何组合所有的月/日/小时/分钟信息,所以所有的数据图,我也不知道如何将月/日放在x轴上。在
为了让你展示的代码能正常工作,我不得不花了不少时间。在
然后我可以从3列中创建一个日期。在
最后,我将重点放在绘图的格式上。在
真的有两个问题。在
如需有关如何设置绘图格式的详细信息,请通过谷歌或搜索“你想做什么”和单词matplotlib。这就是我的例子。在
如果你真的需要从部件创建一个日期时间,你可以这样做:
然而,在你的情况下似乎没有必要。实际上,一次只创建一个datetime对象要容易得多,而不是创建基本datetime对象并添加新部分:
^{pr2}$相关问题 更多 >
编程相关推荐