From 79c0aa9bc2ad8ca6ee8233304e6a40e6b1fe1800 Mon Sep 17 00:00:00 2001 From: Alexander Voishchev Date: Mon, 27 Dec 2021 17:02:11 -0700 Subject: [PATCH] Fixed rows order in BMUHitsView and HitMapView to match the View2D feature maps --- sompy/visualization/bmuhits.py | 8 +++++--- sompy/visualization/hitmap.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sompy/visualization/bmuhits.py b/sompy/visualization/bmuhits.py index d382fc6..faacb6b 100644 --- a/sompy/visualization/bmuhits.py +++ b/sompy/visualization/bmuhits.py @@ -3,6 +3,7 @@ import matplotlib import numpy as np from matplotlib import pyplot as plt +from itertools import chain from .mapview import MapView @@ -59,11 +60,12 @@ def show(self, som, anotate=True, onlyzeros=False, labelsize=7, cmap="jet", loga ax.set_yticklabels([]) ax.set_xticklabels([]) plt.colorbar(pl) - #plt.show() elif som.codebook.lattice == "hexa": - ax, cents = plot_hex_map(mp[::-1], colormap=cmap, fig=self._fig) + ax, cents = plot_hex_map(mp, colormap=cmap, fig=self._fig) if anotate: - self._set_labels(cents, ax, reversed(counts), onlyzeros, labelsize, hex=True) + reversedcounts = np.array(counts[::-1]) + orderedcounts = list(chain.from_iterable(np.flip(reversedcounts.reshape(msz[0], msz[1])[::],axis=0))) + self._set_labels(cents, ax, orderedcounts, onlyzeros, labelsize, hex=True) #plt.show() #return ax, cents diff --git a/sompy/visualization/hitmap.py b/sompy/visualization/hitmap.py index a737440..3f861b0 100644 --- a/sompy/visualization/hitmap.py +++ b/sompy/visualization/hitmap.py @@ -2,6 +2,7 @@ from sompy.visualization.plot_tools import plot_hex_map from matplotlib import pyplot as plt import numpy as np +from itertools import chain from .mapview import MapView @@ -42,16 +43,18 @@ def show(self, som, data=None, anotate=True, onlyzeros=False, labelsize=7, cmap= if anotate: # TODO: Fix position of the labels self._set_labels(cents, ax, clusters[proj], onlyzeros, labelsize, hex=False) - else: cents = som.bmu_ind_to_xy(np.arange(0, msz[0]*msz[1])) if anotate: # TODO: Fix position of the labels - self._set_labels(cents, ax, clusters, onlyzeros, labelsize, hex=False) + orderedclusters = list(chain.from_iterable(np.flip(clusters.reshape(msz[0], msz[1])[::],axis=0))) + self._set_labels(cents, ax, orderedclusters, onlyzeros, labelsize, hex=False) - plt.imshow(np.flip(clusters.reshape(msz[0], msz[1])[::],axis=0), alpha=0.5) + plt.axis('off') + plt.imshow(clusters.reshape(msz[0], msz[1])[::], alpha=0.5) elif som.codebook.lattice == "hexa": - ax, cents = plot_hex_map(np.flip(clusters.reshape(msz[0], msz[1])[::], axis=0), fig=self._fig, colormap=cmap, colorbar=False) + ax, cents = plot_hex_map(clusters.reshape(msz[0], msz[1])[::], fig=self._fig, colormap=cmap, colorbar=False) if anotate: - self._set_labels(cents, ax, reversed(clusters), onlyzeros, labelsize, hex=True) \ No newline at end of file + orderedclusters = list(chain.from_iterable(np.flip(clusters[::-1].reshape(msz[0], msz[1])[::],axis=0))) + self._set_labels(cents, ax, orderedclusters, onlyzeros, labelsize, hex=True)