-
Notifications
You must be signed in to change notification settings - Fork 4
/
highs_lows.py
47 lines (39 loc) · 1.39 KB
/
highs_lows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Author: Bojan G. Kalicanin
# Date: 26-Dec-2016
# Analysis of high and low temperatures.
import csv
from matplotlib import pyplot as plt
from datetime import datetime
# Get dates, high, and low temperatures from file.
fig = plt.figure(dpi=100, figsize=(10, 9))
filenames = ['sitka_weather_2014.csv', 'death_valley_2014.csv']
for filename in filenames:
#filename = 'death_valley_2014.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
dates, highs, lows = [], [], []
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)
# Plot data.
plt.plot(dates, highs, c='red', alpha=0.5)
plt.plot(dates, lows, c='blue', alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor='blue', alpha=0.1)
# Format plot.
title = "Daily high and low temperatures - 2014\nDeath Valley, CA"
plt.title(title, fontsize=24)
plt.xlabel('', fontsize=16)
fig.autofmt_xdate()
plt.ylabel("Temperature (F)", fontsize=16)
plt.tick_params(axis='both', which='major', labelsize=16)
plt.axis([None, None, 15, 120])
plt.show()