代码实现:
import csv
from matplotlib import pyplot as plt
from datetime import datetime
date=[]
airmax=[]
airmin=[]
with open(r'C:\Users\Administrator\Desktop\新建文本文档 (3).csv') as cs:
read=csv.reader(cs)
header=next(read)
for i in read:
date.append(datetime.strptime(i[3],'%Y/%m/%d'))#datetime.strptime(),转换成日期格式,第一个参数是所需的日期字符串,第二参数是告诉python如何设置字符串
airmax.append(int(i[0]))
airmin.append(int(i[1]))
print(airmax)
print(date)
fig=plt.figure(dpi=80,figsize=(10,6))
plt.plot(date,airmax,c='red')
plt.plot(date,airmin)
fig.autofmt_xdate() #设置x轴日期自动适应占位,防止重叠
plt.fill_between(date,airmax,airmin,facecolor='yellow',alpha=0.1)#填充最大最小值区间的范围,facecolor颜色,alpha色度深浅
plt.show()
红尘往事,一切随风!