目标一:制作两个城市最高温和最低温对比图
# 代码如下:
import matplotlib.pyplot as plt
from datetime import datetime
import csv
def get_weather_data(filename, dates, highs, lows):
'''get the highs and lows from a data file'''
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
for row in reader:
try:
current_date = datetime.strptime(row[0], '%Y-%m-%d')
high = int(row[1])
low = int(row[3])
except ValueError:
print(current_date, 'missing data')
else:
dates.append(current_date)
highs.append(high)
lows.append(low)
# Get weather data for Sitka
dates, highs, lows = [], [], []
get_weather_data('sitka_weather_2014.csv', dates, highs, lows)
# Plot weather data for Sitka
fig = plt.figure(dpi=128, figsize=(10,6))
plt.plot(dates, highs, c='red', alpha=0.6)
plt.plot(dates, lows, c='blue', alpha=0.6

该博客介绍如何使用Python的matplotlib库从CSV文件中读取天气数据,并绘制两个城市(Sitka, AK 和 Death Valley, CA)2014年的最高温和最低温度对比折线图。通过get_weather_data函数解析CSV文件,然后使用plot和fill_between方法展示数据,最后调整图表样式和标注。"
50804188,5475135,Robot Framework入门教程全解析,"['RobotFrameWork', '自动化测试', 'Oracle数据库', '测试框架', '网页测试']
最低0.47元/天 解锁文章
4284

被折叠的 条评论
为什么被折叠?



