Skip to content

Commit c026fed

Browse files
Fix setting vmin vmax (#307)
2 parents a0e579a + 88c018b commit c026fed

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning][].
2525
- scale parameter was ignored for single-scale images (#301)
2626
- Changes to support for dask-expr (#283)
2727
- Added error handling for non-existent elements (#305)
28+
- Specifying vmin and vmax properly clips image data (#307)
2829

2930
## [0.2.3] - 2024-07-03
3031

src/spatialdata_plot/pl/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,11 @@ def _prepare_cmap_norm(
376376
cmap.set_bad("lightgray" if na_color is None else na_color)
377377

378378
if norm is None:
379-
norm = Normalize(vmin=vmin, vmax=vmax)
379+
norm = Normalize(vmin=vmin, vmax=vmax, clip=True)
380380
elif isinstance(norm, Normalize) or not norm:
381381
pass # TODO
382382
elif vcenter is None:
383-
norm = Normalize(vmin=vmin, vmax=vmax)
383+
norm = Normalize(vmin=vmin, vmax=vmax, clip=True)
384384
else:
385385
norm = TwoSlopeNorm(vmin=vmin, vmax=vmax, vcenter=vcenter)
386386

76.6 KB
Loading
76.6 KB
Loading

tests/pl/test_render_images.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import scanpy as sc
55
import spatialdata_plot # noqa: F401
6+
from matplotlib import pyplot as plt
7+
from matplotlib.colors import Normalize
68
from spatial_image import to_spatial_image
79
from spatialdata import SpatialData
810

@@ -68,6 +70,17 @@ def test_plot_can_render_two_channels_str_from_image(self, sdata_blobs_str: Spat
6870
def test_plot_can_render_two_channels_str_from_multiscale_image(self, sdata_blobs_str: SpatialData):
6971
sdata_blobs_str.pl.render_images(element="blobs_multiscale_image", channel=["c1", "c2"]).pl.show()
7072

73+
def test_plot_can_pass_vmin_vmax(self, sdata_blobs: SpatialData):
74+
fig, axs = plt.subplots(ncols=2, figsize=(6, 3))
75+
sdata_blobs.pl.render_images(element="blobs_image", channel=1).pl.show(ax=axs[0])
76+
sdata_blobs.pl.render_images(element="blobs_image", channel=1, vmin=0, vmax=0.4).pl.show(ax=axs[1])
77+
78+
def test_plot_can_pass_normalize(self, sdata_blobs: SpatialData):
79+
fig, axs = plt.subplots(ncols=2, figsize=(6, 3))
80+
norm = Normalize(vmin=0, vmax=0.4, clip=True)
81+
sdata_blobs.pl.render_images(element="blobs_image", channel=1).pl.show(ax=axs[0])
82+
sdata_blobs.pl.render_images(element="blobs_image", channel=1, norm=norm).pl.show(ax=axs[1])
83+
7184
def test_plot_can_pass_color_to_single_channel(self, sdata_blobs: SpatialData):
7285
sdata_blobs.pl.render_images(element="blobs_image", channel=1, palette="red").pl.show()
7386

0 commit comments

Comments
 (0)