Skip to content

Commit 23010b9

Browse files
authored
Fix scale parameter for polygons with datashader (#555)
1 parent e53779a commit 23010b9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/spatialdata_plot/pl/render.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ def _render_shapes(
394394
scale = radius_numeric * render_params.scale
395395
shapes.loc[is_point, "geometry"] = _geometry[is_point].buffer(scale.to_numpy())
396396

397+
# Handle polygon/multipolygon scaling
398+
is_polygon = _geometry.type.isin(["Polygon", "MultiPolygon"])
399+
if is_polygon.any() and render_params.scale != 1.0:
400+
from shapely import affinity
401+
402+
shapes.loc[is_polygon, "geometry"] = _geometry[is_polygon].apply(
403+
lambda geom: affinity.scale(geom, xfact=render_params.scale, yfact=render_params.scale)
404+
)
405+
397406
# apply transformations to the individual points
398407
tm = trans.get_matrix()
399408
transformed_geometry = shapes["geometry"].transform(
21.4 KB
Loading

tests/pl/test_render_shapes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def test_plot_can_color_from_geodataframe(self, sdata_blobs: SpatialData):
242242
def test_plot_can_scale_shapes(self, sdata_blobs: SpatialData):
243243
sdata_blobs.pl.render_shapes(element="blobs_circles", scale=0.5).pl.show()
244244

245+
def test_plot_can_scale_polygons_datashader(self, sdata_blobs: SpatialData):
246+
# Regression test for #473: scale parameter had no effect on polygons with datashader
247+
sdata_blobs.pl.render_shapes(element="blobs_polygons", method="datashader", scale=2.0).pl.show()
248+
245249
def test_plot_can_filter_with_groups(self, sdata_blobs: SpatialData):
246250
_, axs = plt.subplots(nrows=1, ncols=2, layout="tight")
247251

0 commit comments

Comments
 (0)