当前位置: 代码迷 >> 综合 >> time data ‘2018/1/1‘ does not match format ‘%Y-%m-%d‘
  详细解决方案

time data ‘2018/1/1‘ does not match format ‘%Y-%m-%d‘

热度:35   发布时间:2024-03-06 13:51:12.0

import csv
from matplotlib import pyplot as plt
from datetime import datetime
filename = 'sitka_weather_2018_simple.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)
    #从文件获取最高气温
    dates,highs = [],[]
    for row in reader:
        current_date = datetime.strptime(row[2],"%Y-%m-%d")
        dates.append(current_date)
        high = int(row[5])
        highs.append(high)
    print(highs)
    #根据数据绘制图形
    fig = plt.figure(dpi=128,figsize = (10,6))
    plt.plot(dates,highs,c='red')
    #设置图形格式
    plt.title("Daily high temperatures,2018",fontsize = 24)
    plt.xlabel('',fontsize =16)
    plt.ylabel('Temperature (F)',fontsize =16)
    fig.autofmt_xdate()
    plt.tick_params(axis='both',which='major',labelsize=16)
    plt.show()
 

  相关解决方案