Skip to content

Commit

Permalink
ListedColormap: don't pass N colors
Browse files Browse the repository at this point in the history
  • Loading branch information
mathause committed Nov 22, 2024
1 parent e510a9e commit a231840
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _color_palette(cmap, n_colors):
colors_i = np.linspace(0, 1.0, n_colors)
if isinstance(cmap, list | tuple):
# we have a list of colors
cmap = ListedColormap(cmap, N=n_colors)
cmap = ListedColormap(cmap)
pal = cmap(colors_i)
elif isinstance(cmap, str):
# we have some sort of named palette
Expand All @@ -151,7 +151,7 @@ def _color_palette(cmap, n_colors):
pal = sns.color_palette(cmap, n_colors=n_colors)
except ValueError:
# or maybe we just got a single color as a string
cmap = ListedColormap([cmap], N=n_colors)
cmap = ListedColormap([cmap] * n_colors)
pal = cmap(colors_i)
else:
# cmap better be a LinearSegmentedColormap (e.g. viridis)
Expand Down

0 comments on commit a231840

Please sign in to comment.