Skip to content

Commit 9ef582e

Browse files
committed
bugfix
1 parent 538d081 commit 9ef582e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/spatialdata_plot/pl/render.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ def _get_collection_shape(
180180
)
181181
cax = ax.add_collection(_cax)
182182

183-
palette = ListedColormap(set(color_vector)) if render_params.palette is None else render_params.palette
183+
# Using dict.fromkeys here since set returns in arbitrary order
184+
palette = ListedColormap(dict.fromkeys(color_vector)) if render_params.palette is None else render_params.palette
184185

185186
_ = _decorate_axs(
186187
ax=ax,

src/spatialdata_plot/pl/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,11 @@ def _get_palette(
839839

840840
if isinstance(palette, str):
841841
cmap = plt.get_cmap(palette)
842-
palette = [to_hex(x) for x in cmap(np.linspace(0, 1, len_cat), alpha=alpha)]
843842
elif isinstance(palette, ListedColormap):
844-
palette = [to_hex(x) for x in palette(np.linspace(0, 1, len_cat), alpha=alpha)]
843+
cmap = palette
845844
else:
846845
raise TypeError(f"Palette is {type(palette)} but should be string or `ListedColormap`.")
846+
palette = [to_hex(np.round(x, 5)) for x in cmap(np.linspace(0, 1, len_cat), alpha=alpha)]
847847

848848
return dict(zip(categories, palette))
849849

0 commit comments

Comments
 (0)