-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_global.py
59 lines (46 loc) · 1.96 KB
/
plot_global.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
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import colorsys
def read_global_temperature(filename):
return np.genfromtxt(filename, delimiter=',', usemask=True)
def read_sonorities(filename, temperatures_filename):
with open(filename, 'r') as f:
next(f)
data = [line.strip('\n').split(',') for line in f]
with open(temperatures_filename, 'r') as f:
next(f)
names = [line.strip().split(',')[0] for line in f if '--' not in line]
data = [line for line in data if line[0] in names]
# return [(lon, lat, sonority index)]
return [[float(line[i]) for line in data] for i in (1, 2, 7)]
def new_cmap(cm_object, saturation_factor, lightness_factor):
my_cmap = cm_object(np.arange(cm_object.N))
my_cmap = np.array([colorsys.rgb_to_hls(*i) for i in my_cmap[:, 0:3]])
my_cmap[:, 1] *= lightness_factor
my_cmap[:, 2] *= saturation_factor
my_cmap = np.minimum(my_cmap, 1)
my_cmap = np.array([colorsys.hls_to_rgb(*i) for i in my_cmap])
my_cmap = ListedColormap(my_cmap)
return my_cmap
t = read_global_temperature('data/temperature_global.csv')
sx, sy, sv = read_sonorities('data/sonorities.csv', 'data/temperatures.csv')
# plt.hist(t.flatten(), bins=30), plt.show()
t = np.power(t - np.nanmin(t) + 0.1, 1.6)
t = t / np.nanmax(t)
# plt.hist(t.flatten(), bins=30), plt.show()
plt.rcParams['figure.figsize'] = (20, 10)
fig = plt.figure()
ax_t = fig.add_subplot(111)
ax_s = fig.add_subplot(111, frame_on=False)
cm_t = new_cmap(plt.cm.inferno, 0.65, 0.65)
cm_s = new_cmap(plt.cm.coolwarm, 1, 0.9)
ax_t.imshow(t, origin='lower', aspect='auto', cmap=cm_t, vmin=-0.5, vmax=1.5)
ax_s.scatter(sx, sy, c=sv, cmap=cm_s, s=2)
ax_s.set_xlim(-180, 180)
ax_s.set_ylim(-60, 90)
ax_t.axis('off')
ax_s.axis('off')
plt.savefig('figures/global.png', bbox_inches='tight', pad_inches=0.3, dpi=150)
# plt.savefig('figures/global.pdf', bbox_inches='tight', pad_inches=0.3, dpi=150)
plt.show()