diff --git a/CHANGELOG.md b/CHANGELOG.md index 58514ae9..f61f9d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning][]. - Now dropping index when plotting shapes after spatial query (#177) - Points are now being correctly rotated (#198) - User can now pass Colormap objects to the cmap argument in render_images. When only one cmap is given for 3 channels, it is now applied to each channel (#188, #194) +- Labels can now be colored by a continuous variable without setting `norm` (#201) ## [0.0.6] - 2023-11-06 diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index c3eab57f..4d3c330e 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -353,7 +353,9 @@ def _prepare_cmap_norm( cmap.set_bad("lightgray" if na_color is None else na_color) - if isinstance(norm, Normalize) or not norm: + if norm is None: + norm = Normalize(vmin=vmin, vmax=vmax) + elif isinstance(norm, Normalize) or not norm: pass # TODO elif vcenter is None: norm = Normalize(vmin=vmin, vmax=vmax) diff --git a/tests/_images/Labels_can_color_labels_by_continuous_variable.png b/tests/_images/Labels_can_color_labels_by_continuous_variable.png new file mode 100644 index 00000000..30b3fa8b Binary files /dev/null and b/tests/_images/Labels_can_color_labels_by_continuous_variable.png differ diff --git a/tests/pl/test_render_labels.py b/tests/pl/test_render_labels.py index fe0ef717..3db06a10 100644 --- a/tests/pl/test_render_labels.py +++ b/tests/pl/test_render_labels.py @@ -70,3 +70,6 @@ def test_plot_can_stack_render_labels(self, sdata_blobs: SpatialData): ) .pl.show() ) + + def test_plot_can_color_labels_by_continuous_variable(self, sdata_blobs: SpatialData): + sdata_blobs.pl.render_labels("blobs_labels", color="channel_0_sum").pl.show()