forked from ChaoticRoman/numpy_scipy_matplotlib_workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyear3D_2.py
More file actions
37 lines (29 loc) · 977 Bytes
/
year3D_2.py
File metadata and controls
37 lines (29 loc) · 977 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
35
36
37
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
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)
X, Y = np.meshgrid(x, y)
avg = temperature.mean()
dt2day_of_year = lambda dt: dt.timetuple().tm_yday
T = np.zeros_like(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 = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, T, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
fig.colorbar(surf)
plt.show()