Skip to content

Commit

Permalink
Fix blobs on rect lattice and axis lim bug
Browse files Browse the repository at this point in the history
When lattice is rect, the blob positions need to be flipped to match
the hexagons positions.

The axis limits were inverting the axis. I think the reason might be
related to matplotlib/matplotlib#8693. This is solved in this commit.
  • Loading branch information
dfhssilva committed Feb 7, 2021
1 parent bc80803 commit 2e898b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sompy/visualization/umatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def _set_blob(self, umat, coord, ax, X=None, Y=None, hex=False):
blobs[:, 2] = blobs[:, 2] * sqrt(2)
if hex:
blobs[:, :2] = rectxy_to_hexaxy(blobs[:, :2].astype(int), X, Y)
else:
blobs[:, :2] = np.flip(blobs[:, :2], axis=1)
sel_points = list()

for blob in blobs:
Expand All @@ -89,10 +91,10 @@ def _set_blob(self, umat, coord, ax, X=None, Y=None, hex=False):
sel_points.append(sel_point[:, 0])
if hex:
ax.set_xlim([-0.5, umat.shape[1]])
ax.set_ylim([0.6, -((umat.shape[0] - 1) * sqrt(3)/2 + 0.6)])
ax.set_ylim([-(((umat.shape[0] - 1) * sqrt(3)/2) + 1/sqrt(3)), 1/sqrt(3)])
else:
ax.set_xlim([-0.5, umat.shape[1] - 0.5])
ax.set_ylim([-0.5, umat.shape[0] - 0.5])
ax.set_ylim([umat.shape[0] - 0.5, -0.5])


def show(self, som, distance=1, row_normalized=False, show_data=False,
Expand All @@ -113,7 +115,7 @@ def show(self, som, distance=1, row_normalized=False, show_data=False,
warn("For hexagonal lattice, distance < sqrt(3) produces a null U-matrix.")
umat = self.build_u_matrix(som, distance=distance, row_normalized=row_normalized)
msz = som.codebook.mapsize
proj = som.project_data(som.data_raw)
proj = som._bmu[0]
coord = som.bmu_ind_to_xy(proj)[:, :2]
sel_points = list()

Expand Down

0 comments on commit 2e898b5

Please sign in to comment.