Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid error if only one class present in result #208

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading