Skip to content

Commit dc7aaec

Browse files
timtreisclaude
andauthored
Fix datashader elements invisible with non-square aspect ratios (#544)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6be1b41 commit dc7aaec

6 files changed

+16
-2
lines changed

src/spatialdata_plot/pl/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,13 +2895,16 @@ def _get_extent_and_range_for_datashader_canvas(
28952895
]
28962896
)
28972897

2898-
# compute canvas size in pixels close to the actual image size to speed up computation
2898+
# Compute canvas size in pixels, capped at the figure's display resolution.
2899+
# Using np.max ensures the canvas never exceeds display pixels on either axis,
2900+
# preventing pixel-based operations (spread, line_width) from being downscaled
2901+
# to sub-pixel size when the data aspect ratio differs from the figure's.
28992902
plot_width = x_ext[1] - x_ext[0]
29002903
plot_height = y_ext[1] - y_ext[0]
29012904
plot_width_px = int(round(fig_params.fig.get_size_inches()[0] * fig_params.fig.dpi))
29022905
plot_height_px = int(round(fig_params.fig.get_size_inches()[1] * fig_params.fig.dpi))
29032906
factor: float
2904-
factor = np.min([plot_width / plot_width_px, plot_height / plot_height_px])
2907+
factor = np.max([plot_width / plot_width_px, plot_height / plot_height_px])
29052908
plot_width = int(np.round(plot_width / factor))
29062909
plot_height = int(np.round(plot_height / factor))
29072910

3.64 KB
Loading
986 Bytes
Loading
41 Bytes
Loading
431 Bytes
Loading

tests/pl/test_render_points.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,14 @@ def test_plot_datashader_single_category_points(sdata_blobs: SpatialData):
606606
method="datashader",
607607
size=5,
608608
).pl.show()
609+
610+
611+
def test_datashader_points_visible_with_nonuniform_scale(sdata_blobs: SpatialData):
612+
"""Datashader points must remain visible when data has a non-square aspect ratio.
613+
614+
Regression test for https://github.com/scverse/spatialdata-plot/issues/445.
615+
Before the fix, the datashader canvas was oversized on the longer axis, causing
616+
spread(px) to be downscaled to sub-pixel size on display.
617+
"""
618+
_set_transformations(sdata_blobs["blobs_points"], {"global": Scale([1, 5], axes=("x", "y"))})
619+
sdata_blobs.pl.render_points("blobs_points", method="datashader", color="black").pl.show()

0 commit comments

Comments
 (0)