Skip to content

Commit 0dc2289

Browse files
timtreisclaude
andcommitted
Add visual tests for transparent cmap with shapes rendering
Add test_plot_transparent_cmap_shapes_matplotlib and test_plot_transparent_cmap_shapes_datashader to verify that shapes with value=0 are rendered transparently over an image when using set_zero_in_cmap_to_transparent, for both rendering backends. Placeholder baselines included — CI will generate the real ones. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a4337eb commit 0dc2289

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

70 Bytes
Loading
70 Bytes
Loading

tests/pl/test_utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def test_plot_colnames_that_are_valid_matplotlib_greyscale_colors_are_not_evalua
5858
sdata_blobs.pl.render_shapes("blobs_polygons", color=colname).pl.show()
5959

6060
def test_plot_can_set_zero_in_cmap_to_transparent(self, sdata_blobs: SpatialData):
61-
from spatialdata_plot.pl.utils import set_zero_in_cmap_to_transparent
62-
6361
# set up figure and modify the data to add 0s
6462
_, axs = plt.subplots(nrows=1, ncols=2, layout="tight")
6563
sdata_blobs.tables["table"].obs["my_var"] = list(range(len(sdata_blobs.tables["table"].obs)))
@@ -79,6 +77,21 @@ def test_plot_can_set_zero_in_cmap_to_transparent(self, sdata_blobs: SpatialData
7977
ax=axs[1], colorbar=False
8078
)
8179

80+
def _render_transparent_cmap_shapes(self, sdata_blobs: SpatialData, method: str):
81+
new_cmap = set_zero_in_cmap_to_transparent(cmap="viridis")
82+
sdata_blobs["table"].obs["region"] = pd.Categorical(["blobs_polygons"] * sdata_blobs["table"].n_obs)
83+
sdata_blobs["table"].uns["spatialdata_attrs"]["region"] = "blobs_polygons"
84+
sdata_blobs.shapes["blobs_polygons"]["value"] = [0.0, 2.0, 3.0, 4.0, 5.0]
85+
sdata_blobs.pl.render_images("blobs_image").pl.render_shapes(
86+
"blobs_polygons", color="value", cmap=new_cmap, method=method
87+
).pl.show(colorbar=False)
88+
89+
def test_plot_transparent_cmap_shapes_matplotlib(self, sdata_blobs: SpatialData):
90+
self._render_transparent_cmap_shapes(sdata_blobs, method="matplotlib")
91+
92+
def test_plot_transparent_cmap_shapes_datashader(self, sdata_blobs: SpatialData):
93+
self._render_transparent_cmap_shapes(sdata_blobs, method="datashader")
94+
8295

8396
@pytest.mark.parametrize(
8497
"color_result",

0 commit comments

Comments
 (0)