一、安装 Pygal
找到 Python/scripts/
python -m pip install --user pygal
二、下载数据
2.1 下载可用数据并用图表展示
import csv
from matplotlib import pyplot as plt
# 添加日期
from datetime import datetime
filename = 'sitka_weather_2014.csv'
f = open(filename)
从文件中获取最高气温和日期
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
获取最高气温和日期
dates, highs = [], []
for row in reader:
current_date = datetime.strptime(row[0], "%Y-%m-%d")
dates.append(current_date)
high = int(row[1])
highs.append(high)
print(highs)
fig = plt.figure(dpi=128, figsize=(10, 6))
plt