import csv
import matplotlib.pyplot as plt
from datetime import datetime
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
filename = 'sitka_weather_07-2018_simple.csv'
highs = []
dates = []
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
# print(header_row)
for row in reader:
current_time = datetime.strptime(row[2],'%Y-%m-%d')
high = int(row[5])
highs.append(high)
dates.append(current_time)
print(highs)
# for index,column_header in enumerate(header_row):
# print(index,column_header)
fig ,ax =plt.subplots()
ax.plot(dates,highs,c='red')
fig.autofmt_xdate() #用来获取倾斜的标签,防止标签遮挡
ax.set_title("2018年七月每日最高温度",fontsize=24)
ax.set_xlabel('',fontsize='16')
ax.set_ylabel('温度(F)',fontsize='16')
plt.show()
可视化效果: