Skip to content

Commit

Permalink
avoid error if only one class present in result
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegerickx committed Oct 21, 2024
1 parent 8596f0d commit ef8aa45
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions notebooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def scale_rgb(color):

# Get class labels and set colorbar boundaries
classlabels = list(lut.keys())
bounds = list(np.unique(arr_classif)) # Class boundaries
bounds = np.linspace(0, len(classlabels), len(classlabels) + 1)

# Define a norm for the colormap
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
Expand All @@ -894,14 +894,12 @@ def scale_rgb(color):
ax.imshow(arr_classif, cmap=cmap, norm=norm)

# Create a colorbar with class labels
bounds_colorbar = np.linspace(0, len(classlabels), len(classlabels) + 1)
norm_colorbar = mpl.colors.BoundaryNorm(bounds_colorbar, cmap.N)
cb = mpl.colorbar.ColorbarBase(
ax2,
cmap=cmap,
norm=norm_colorbar,
norm=norm,
spacing="proportional",
boundaries=bounds_colorbar,
boundaries=bounds,
# Middle of each class
ticks=np.arange(len(classlabels)) + 0.5,
format="%1i",
Expand Down

0 comments on commit ef8aa45

Please sign in to comment.