-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbmuhits.py
More file actions
executable file
·54 lines (40 loc) · 1.72 KB
/
bmuhits.py
File metadata and controls
executable file
·54 lines (40 loc) · 1.72 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
49
50
51
52
53
54
from collections import Counter
import matplotlib
import numpy as np
from matplotlib import pyplot as plt
from mapview import MapView
class BmuHitsView(MapView):
def _set_labels(self, cents, ax, labels, onlyzeros, fontsize):
for i, txt in enumerate(labels):
if onlyzeros == True:
if txt > 0:
txt = ""
ax.annotate(txt, (cents[i, 1] + 0.5, cents[-(i+1), 0] + 0.5), va="center", ha="center", size=fontsize)
def show(self, som, s_bmu, anotate=True, onlyzeros=False, labelsize=7, cmap="jet", logaritmic = False):
(self.width, self.height, indtoshow, no_row_in_plot, no_col_in_plot,
axis_num) = self._calculate_figure_params(som, 1, 1)
self.prepare()
ax = plt.gca()
counts = Counter(s_bmu)
counts = [counts.get(x, 0) for x in range(som.codebook.mapsize[0] * som.codebook.mapsize[1])]
mp = np.array(counts).reshape(som.codebook.mapsize[0],
som.codebook.mapsize[1])
if not logaritmic:
norm = matplotlib.colors.Normalize(
vmin=0,
vmax=np.max(mp.flatten()),
clip=True)
else:
norm = matplotlib.colors.LogNorm(
vmin=1,
vmax=np.max(mp.flatten()))
msz = som.codebook.mapsize
cents = som.bmu_ind_to_xy(np.arange(0, msz[0] * msz[1]))
if anotate:
self._set_labels(cents, ax, counts, onlyzeros, labelsize)
pl = plt.pcolor(mp[::-1], norm=norm, cmap=cmap)
plt.axis([0, som.codebook.mapsize[1], 0, som.codebook.mapsize[0]])
ax.set_yticklabels([])
ax.set_xticklabels([])
plt.colorbar(pl)
plt.show()