import csv
import matplotlib.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)
# print(header_row)
# for index,column_header in enumerate(header_row):
# print(index,column_header)
dates, highs, lows = [], [], []
for row in reader:
high = int(row[5])
highs.append(high)
date = datetime.strptime(row[2], '%Y-%m-%d')
dates.append(date)
low = int(row[6])
lows.append(low)
# print(highs)
plt.style.use('seaborn')
fig, ax = plt.subplots()
ax.plot(dates, highs, c='red')
ax.plot(dates, lows, c='blue')
ax.fill_between(dates, highs, lows, facecolor='yellow')
ax.set_title('最高气温', fontsize=25)
ax.set_xlabel('', fontsize=15)
fig.autofmt_xdate()
ax.set_ylabel('气温', fontsize=15)
ax.tick_params(axis='both', which='major', labelsize=15)
plt.show()
#数据缺失可用 try-except-else