diff --git a/src/spatialdata_plot/pl/render.py b/src/spatialdata_plot/pl/render.py index 3392500f..5334e287 100644 --- a/src/spatialdata_plot/pl/render.py +++ b/src/spatialdata_plot/pl/render.py @@ -342,18 +342,20 @@ def _render_shapes( agg = cvs.polygons(transformed_element, geometry="geometry", agg=ds.count()) # render outlines if needed + # outline_linewidth is in points (1pt = 1/72 inch); datashader line_width is in canvas pixels + ds_lw_factor = fig_params.fig.dpi / 72 assert len(render_params.outline_alpha) == 2 # shut up mypy if render_params.outline_alpha[0] > 0: agg_outlines = cvs.line( transformed_element, geometry="geometry", - line_width=render_params.outline_params.outer_outline_linewidth, + line_width=render_params.outline_params.outer_outline_linewidth * ds_lw_factor, ) if render_params.outline_alpha[1] > 0: agg_inner_outlines = cvs.line( transformed_element, geometry="geometry", - line_width=render_params.outline_params.inner_outline_linewidth, + line_width=render_params.outline_params.inner_outline_linewidth * ds_lw_factor, ) ds_span = None diff --git a/tests/_images/Shapes_datashader_can_render_shapes_with_double_outline.png b/tests/_images/Shapes_datashader_can_render_shapes_with_double_outline.png index cbc6c5e4..5475f24f 100644 Binary files a/tests/_images/Shapes_datashader_can_render_shapes_with_double_outline.png and b/tests/_images/Shapes_datashader_can_render_shapes_with_double_outline.png differ diff --git a/tests/pl/test_render_shapes.py b/tests/pl/test_render_shapes.py index 8065ca9e..5533b6b0 100644 --- a/tests/pl/test_render_shapes.py +++ b/tests/pl/test_render_shapes.py @@ -999,3 +999,17 @@ def test_plot_datashader_single_category(sdata_blobs: SpatialData): sdata_blobs["table"] = table sdata_blobs.pl.render_shapes(element="blobs_polygons", color="category", method="datashader").pl.show() + + +def test_datashader_outline_width_uses_points_units(sdata_blobs: SpatialData): + """Datashader outlines should scale with DPI like matplotlib (points, not raw pixels). + + Regression test for https://github.com/scverse/spatialdata-plot/issues/493. + """ + sdata_blobs.pl.render_shapes( + element="blobs_polygons", method="datashader", outline_alpha=1.0, outline_width=10.0 + ).pl.show() + + sdata_blobs.pl.render_shapes( + element="blobs_polygons", method="datashader", outline_alpha=1.0, outline_width=(8.0, 3.0) + ).pl.show()