diff --git a/CHANGELOG.md b/CHANGELOG.md index 5af97c85..cc2cdb2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning][]. ### Fixed -- +- Giving a custom colormap when rendering a multiscale image now works (#586) ## [0.2.6] - 2024-09-04 diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index 33a103da..fddc0921 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -1897,18 +1897,18 @@ def _validate_image_render_params( if isinstance(palette := param_dict["palette"], list): if len(palette) == 1: - palette_length = len(channel) if channel is not None else len(spatial_element.c) + palette_length = len(channel) if channel is not None else len(spatial_element_ch) palette = palette * palette_length - if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element.c): + if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element_ch): palette = None element_params[el]["palette"] = palette element_params[el]["na_color"] = param_dict["na_color"] if (cmap := param_dict["cmap"]) is not None: if len(cmap) == 1: - cmap_length = len(channel) if channel is not None else len(spatial_element.c) + cmap_length = len(channel) if channel is not None else len(spatial_element_ch) cmap = cmap * cmap_length - if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element.c): + if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element_ch): cmap = None element_params[el]["cmap"] = cmap element_params[el]["norm"] = param_dict["norm"] diff --git a/tests/_images/Images_can_render_multiscale_image_with_custom_cmap.png b/tests/_images/Images_can_render_multiscale_image_with_custom_cmap.png new file mode 100644 index 00000000..4222e8c4 Binary files /dev/null and b/tests/_images/Images_can_render_multiscale_image_with_custom_cmap.png differ diff --git a/tests/_images/Labels_can_render_given_scale_of_multiscale_labels.png b/tests/_images/Labels_can_render_given_scale_of_multiscale_labels.png index c30e84d6..cb50c54b 100644 Binary files a/tests/_images/Labels_can_render_given_scale_of_multiscale_labels.png and b/tests/_images/Labels_can_render_given_scale_of_multiscale_labels.png differ diff --git a/tests/pl/test_render_images.py b/tests/pl/test_render_images.py index a83f095b..c4e43977 100644 --- a/tests/pl/test_render_images.py +++ b/tests/pl/test_render_images.py @@ -125,3 +125,6 @@ def test_plot_can_stack_render_images(self, sdata_blobs: SpatialData): def test_plot_can_stick_to_zorder(self, sdata_blobs: SpatialData): sdata_blobs.pl.render_shapes().pl.render_images().pl.show() + + def test_plot_can_render_multiscale_image_with_custom_cmap(self, sdata_blobs: SpatialData): + sdata_blobs.pl.render_images("blobs_multiscale_image", channel=0, scale="scale2", cmap="Greys").pl.show()