forked from ChaoticRoman/numpy_scipy_matplotlib_workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyear1.py
More file actions
34 lines (26 loc) · 911 Bytes
/
year1.py
File metadata and controls
34 lines (26 loc) · 911 Bytes
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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from load_data import load_data
from moving_average import moving_average
N = 365
if __name__ == "__main__":
_, dates, data = load_data()
temperature = data[:,0]
first_year, last_year = dates[0].year, dates[-1].year
x = range(first_year, last_year + 1)
y = range(1, 365 + 1)
dt2day_of_year = lambda dt: dt.timetuple().tm_yday
T = np.zeros((len(y), len(x)))
for i, t in enumerate(temperature):
dt = dates[i]
x_i = dt.year - first_year
y_i = dt2day_of_year(dt)
if y_i < 365:
T[y_i,x_i] = t # row (i.e. y) is first index
fig, ax = plt.subplots()
im = ax.imshow(T, origin='lower', interpolation='bicubic',
cmap=cm.jet, vmin=np.min(T), vmax=np.max(T),
extent=[first_year, last_year, 1, 365],
aspect="auto")
plt.show()