Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Binary file modified tests/_images/Points_datashader_can_transform_points.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions tests/pl/test_render_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()