-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitka_highs_lows.py
More file actions
48 lines (41 loc) · 1.4 KB
/
Copy pathsitka_highs_lows.py
File metadata and controls
48 lines (41 loc) · 1.4 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
import csv
import matplotlib.pyplot as plt
from datetime import datetime as dt
filename = 'data/sitka_weather_2018_simple.csv'
# Open the file.
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
# Print headers values.
# print(header_row)
for index, column_header in enumerate(header_row):
print(index, column_header)
# Extracting high temps from reader
dates, lows, highs = [], [], []
for row in reader:
high = int(row[5])
low = int(row[6])
date = dt.strptime(row[2], '%d/%m/%Y')
highs.append(high)
lows.append(low)
dates.append(date)
# Checks.
# print(highs)
# print(lows)
# print(dates)
# Plot the high temperatures.
plt.style.use('seaborn')
fig, ax = plt.subplots()
ax.scatter(dates, highs, c = highs, cmap = plt.cm.Wistia, s = 10, zorder = 10)
ax.scatter(dates, lows, c = lows, cmap = plt.cm.viridis, s = 10, zorder = 10)
ax.plot(dates, highs, c = 'red', zorder = 1, alpha = 0.5)
ax.plot(dates, lows, c = 'blue', zorder = 1, alpha = 0.5)
plt.fill_between(dates, highs, lows, facecolor = 'blue', alpha = 0.1)
# Format plot.
plt.title("Daily high and low temperatures - 2018", 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_weather_2018.png')
plt.show()