Skip to content
Merged
Show file tree
Hide file tree
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: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning][].
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [0.0.5] -tbd

### Added

### Fixed

- Legend order is now deterministic (#143)

## [0.0.4] - 2023-08-11

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def _get_collection_shape(
)
cax = ax.add_collection(_cax)

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

_ = _decorate_axs(
ax=ax,
Expand Down
4 changes: 2 additions & 2 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,11 @@ def _get_palette(

if isinstance(palette, str):
cmap = plt.get_cmap(palette)
palette = [to_hex(x) for x in cmap(np.linspace(0, 1, len_cat), alpha=alpha)]
elif isinstance(palette, ListedColormap):
palette = [to_hex(x) for x in palette(np.linspace(0, 1, len_cat), alpha=alpha)]
cmap = palette
else:
raise TypeError(f"Palette is {type(palette)} but should be string or `ListedColormap`.")
palette = [to_hex(np.round(x, 5)) for x in cmap(np.linspace(0, 1, len_cat), alpha=alpha)]

return dict(zip(categories, palette))

Expand Down