-
Notifications
You must be signed in to change notification settings - Fork 7
/
plot_map.py
79 lines (67 loc) · 2.01 KB
/
plot_map.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.ticker import FuncFormatter
cdict = {'red': [(0.0, 0.0, 0.0),
(0.33, 0.0, 0.0),
(0.66, 1.0, 1.0),
(1.0, 1.0, 1.0)],
'blue': [(0.0, 0.0, 0.0),
(0.33, 1.0, 1.0),
(0.66, 0.0, 0.0),
(1.0, 0.0, 0.0)],
'green': [(0.0, 0.0, 0.0),
(0.33, 0.0, 0.0),
(0.66, 0.0, 0.0),
(1.0, 1.0, 1.0)]}
my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap', cdict, 256)
def scale(x, pos):
'The two args are the value and tick position'
return '%1.1f' % (x / 60.0)
def scale2(x, pos):
'The two args are the value and tick position'
return '%1.1f' % (x / 60.0)
size = int(sys.argv[2])
print sys.argv[1]
#data = np.loadtxt(sys.argv[1]).T
k, x, y, z = np.loadtxt(sys.argv[1], unpack=True)
data = np.zeros((size, size))
m = 0
x_m = 0
y_m = 0
for i in range(0, len(z)):
data[int(round(x[i] * size)), int(round(y[i] * size))] = z[i]
if z[i] > m:
x_m = round(x[i] * size)
y_m = round(y[i] * size)
m = z[i]
data = np.ma.masked_where(data == 0, data)
print "best:"+str(max(z))
def load_points(fname):
p_z, p_y, p_x = np.loadtxt(fname).T
p_x *= size
p_y *= size
p_p_x = []
p_p_y = []
np_p_x = []
np_p_y = []
for i in range(0, len(p_x)):
if p_z[i] == 1.0:
p_p_x += [p_x[i]]
p_p_y += [p_y[i]]
else:
np_p_x += [p_x[i]]
np_p_y += [p_y[i]]
return p_p_x, p_p_y, np_p_x, np_p_y
fig = plt.figure()
im = plt.imshow(data.T, origin='lower', cmap=my_cmap)
im.set_interpolation('nearest')
fig.subplots_adjust(top=0.98)
cb = plt.colorbar()
for t in cb.ax.get_xticklabels():
t.set_fontsize(130)
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(FuncFormatter(scale))
ax.xaxis.set_major_formatter(FuncFormatter(scale2))
plt.savefig('heatmap.pdf')