1、csv文件格式
import csv
from datetime import datetime
import matplotlib.pyplot as plt
filename = 'data/sitka_weather_2014.csv'
with open(filename) as f:
reader = csv.reader(f)
head_row = next(reader) #分析文件头
#for index,column_header in enumerate(head_row): #获取每个元素的索引及值
# print(index,column_header)
#获取日期与最高温度
dates,highs,lows = [],[],[]
for row in reader:
current_date = datetime.strptime(row[0],'%Y-%m-%d')
dates.append(current_date)
high = int(row[1])
highs.append(high)
low = int(row[3])
lows.append(low)
#绘图
plt.style.use('seaborn')
plt.rcParams['font.sans-serif']=['SimHei']
fig, ax = plt.subplots()
ax.plot(dates,highs, c = 'red', alpha = 0.5)
ax.plot(dates,lows, c = 'blue', alpha = 0.5)
ax.fill_between(dates,highs,lows,facecolor='blue',alpha = 0.1)
#设置图形的格式
ax.set_ti