diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index ae55a9c8..6c5aaddf 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -2895,13 +2895,16 @@ def _get_extent_and_range_for_datashader_canvas( ] ) - # compute canvas size in pixels close to the actual image size to speed up computation + # Compute canvas size in pixels, capped at the figure's display resolution. + # Using np.max ensures the canvas never exceeds display pixels on either axis, + # preventing pixel-based operations (spread, line_width) from being downscaled + # to sub-pixel size when the data aspect ratio differs from the figure's. plot_width = x_ext[1] - x_ext[0] plot_height = y_ext[1] - y_ext[0] plot_width_px = int(round(fig_params.fig.get_size_inches()[0] * fig_params.fig.dpi)) plot_height_px = int(round(fig_params.fig.get_size_inches()[1] * fig_params.fig.dpi)) factor: float - factor = np.min([plot_width / plot_width_px, plot_height / plot_height_px]) + factor = np.max([plot_width / plot_width_px, plot_height / plot_height_px]) plot_width = int(np.round(plot_width / factor)) plot_height = int(np.round(plot_height / factor)) diff --git a/tests/_images/Points_datashader_can_transform_points.png b/tests/_images/Points_datashader_can_transform_points.png index 6bd5506f..51813e64 100644 Binary files a/tests/_images/Points_datashader_can_transform_points.png and b/tests/_images/Points_datashader_can_transform_points.png differ diff --git a/tests/_images/Shapes_datashader_can_render_shapes_with_colored_double_outline.png b/tests/_images/Shapes_datashader_can_render_shapes_with_colored_double_outline.png index 8614e760..d5468723 100644 Binary files a/tests/_images/Shapes_datashader_can_render_shapes_with_colored_double_outline.png and b/tests/_images/Shapes_datashader_can_render_shapes_with_colored_double_outline.png differ 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 5475f24f..6bb56592 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/_images/Shapes_datashader_can_render_with_diff_width_outline.png b/tests/_images/Shapes_datashader_can_render_with_diff_width_outline.png index b638716a..e39c24f1 100644 Binary files a/tests/_images/Shapes_datashader_can_render_with_diff_width_outline.png and b/tests/_images/Shapes_datashader_can_render_with_diff_width_outline.png differ diff --git a/tests/pl/test_render_points.py b/tests/pl/test_render_points.py index e0574137..32e0b973 100644 --- a/tests/pl/test_render_points.py +++ b/tests/pl/test_render_points.py @@ -606,3 +606,14 @@ def test_plot_datashader_single_category_points(sdata_blobs: SpatialData): method="datashader", size=5, ).pl.show() + + +def test_datashader_points_visible_with_nonuniform_scale(sdata_blobs: SpatialData): + """Datashader points must remain visible when data has a non-square aspect ratio. + + Regression test for https://github.com/scverse/spatialdata-plot/issues/445. + Before the fix, the datashader canvas was oversized on the longer axis, causing + spread(px) to be downscaled to sub-pixel size on display. + """ + _set_transformations(sdata_blobs["blobs_points"], {"global": Scale([1, 5], axes=("x", "y"))}) + sdata_blobs.pl.render_points("blobs_points", method="datashader", color="black").pl.show()