Skip to content

Commit

Permalink
Merge pull request #133 from alexv71/alexv71-patch-1
Browse files Browse the repository at this point in the history
Fixed rows order in BMUHitsView and HitMapView to match the View2D fe…
  • Loading branch information
sevamoo authored Apr 10, 2022
2 parents 3c659bc + 79c0aa9 commit cba0bca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 5 additions & 3 deletions sompy/visualization/bmuhits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import matplotlib
import numpy as np
from matplotlib import pyplot as plt
from itertools import chain

from .mapview import MapView

Expand Down Expand Up @@ -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
13 changes: 8 additions & 5 deletions sompy/visualization/hitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
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)

0 comments on commit cba0bca

Please sign in to comment.