-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitka_death_valley.py
More file actions
69 lines (60 loc) · 2.29 KB
/
Copy pathsitka_death_valley.py
File metadata and controls
69 lines (60 loc) · 2.29 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import csv
import matplotlib.pyplot as plt
from datetime import datetime as dt
sitka = 'data/sitka_weather_2018_simple.csv'
death_valley = 'data/death_valley_2018_simple.csv'
with open(death_valley) as f:
dv_reader = csv.reader(f)
dv_header_row = next(dv_reader)
# Get dates, and high and low temperatures from this file.
dv_dates, dv_highs, dv_lows = [], [], []
for row in dv_reader:
try:
dv_current_date = dt.strptime(row[dv_header_row.index('DATE')], '%d/%m/%Y')
dv_high = int(row[dv_header_row.index('TMAX')])
dv_low = int(row[dv_header_row.index('TMIN')])
dv_name = str(row[dv_header_row.index('NAME')])
except ValueError:
print(f"Missing data for {dv_current_date}")
else:
dv_highs.append(dv_high)
dv_lows.append(dv_low)
dv_dates.append(dv_current_date)
with open(sitka) as f:
s_reader = csv.reader(f)
s_header_row = next(s_reader)
# Print headers values.
# print(s_header_row)
#for index, column_header in enumerate(s_header_row):
#print(index, column_header)
# Extracting high temps from reader
s_dates, s_lows, s_highs = [], [], []
for row in s_reader:
s_high = int(row[5])
s_low = int(row[6])
s_date = dt.strptime(row[2], '%d/%m/%Y')
s_name = str(row[s_header_row.index('NAME')])
s_highs.append(s_high)
s_lows.append(s_low)
s_dates.append(s_date)
plt.style.use('seaborn')
fig, ax = plt.subplots()
# Plot sitka
ax.plot(s_dates, s_highs, c = 'red', zorder = 1, alpha = 0.5)
ax.plot(s_dates, s_lows, c = 'blue', zorder = 1, alpha = 0.5)
plt.fill_between(s_dates, s_highs, s_lows, facecolor = 'blue',
alpha = 0.1)
# plot death valley
ax.plot(dv_dates, dv_highs, c = 'red', zorder = 1, alpha = 0.5)
ax.plot(dv_dates, dv_lows, c = 'blue', zorder = 1, alpha = 0.5)
plt.fill_between(dv_dates, dv_highs, dv_lows, facecolor = 'red',
alpha = 0.1)
# Format plot.
plt.title(f"Daily high and low temperatures\n{dv_name} and {s_name}",
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.savefig('sitka_death_valley.png')
plt.show()