Skip to content

Fix datashader elements invisible with non-square aspect ratios#544

Merged
timtreis merged 2 commits intomainfrom
fix/datashader-canvas-oversizing
Mar 5, 2026
Merged

Fix datashader elements invisible with non-square aspect ratios#544
timtreis merged 2 commits intomainfrom
fix/datashader-canvas-oversizing

Conversation

@timtreis
Copy link
Member

@timtreis timtreis commented Mar 5, 2026

Summary

  • Fixes Unintuitive almost white color when plotting with datashader #445: datashader points (and other elements) appear invisible when the data has a non-square aspect ratio (e.g. after applying Scale([1, 5]))
  • Root cause: _get_extent_and_range_for_datashader_canvas used np.min to compute the scaling factor, which made the canvas up to ~9× larger than the display on the longer axis. All pixel-based operations (spread, line_width) were then downscaled to sub-pixel size during display
  • Fix: Changed np.minnp.max, ensuring the canvas never exceeds the display resolution on either axis

Details

With np.min, the canvas matched display pixels on the shorter axis but was oversized on the longer one:

Data 500×2500, Figure 640×480 → Canvas 640×3200 (8.7× oversized on y)
spread(px=1) → 3×3 canvas px → 3.0×0.4 display px → invisible

With np.max, the canvas is capped to display resolution:

Data 500×2500, Figure 640×480 → Canvas 100×500 (≤1× on both axes)  
spread(px=1) → 3×3 canvas px → 3×3 display px → visible

Verified no visual quality degradation for shapes, outlines, labels, images, or dense point clouds — the extra canvas pixels produced by np.min were always downscaled away during display and contributed nothing visible.

Test plan

  • Added test_datashader_points_visible_with_nonuniform_scale regression test
  • Visually verified shapes, outlines, labels, and images are unaffected
  • Verified dense point clouds (50k pts) render identically
  • Pre-existing image comparison failures are unrelated (also fail on main)

🤖 Generated with Claude Code

timtreis and others added 2 commits March 5, 2026 22:18
…ents

The canvas sizing used np.min to pick the scaling factor, which preserved
square pixels but could make the canvas many times larger than the display
on one axis. Pixel-based operations (spread, line_width) were then
downscaled to sub-pixel size, making points and outlines invisible.

Using np.max ensures the canvas never exceeds display pixels on either
axis. This fixes visibility with non-square aspect ratios (e.g. scale
transforms) while maintaining visual quality for all element types.

Fixes #445

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timtreis timtreis marked this pull request as ready for review March 5, 2026 21:36
@timtreis timtreis merged commit dc7aaec into main Mar 5, 2026
4 checks passed
@timtreis timtreis deleted the fix/datashader-canvas-oversizing branch March 5, 2026 21:37
@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.00%. Comparing base (6be1b41) to head (49bcda0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #544   +/-   ##
=======================================
  Coverage   84.00%   84.00%           
=======================================
  Files           9        9           
  Lines        2601     2601           
=======================================
  Hits         2185     2185           
  Misses        416      416           
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/utils.py 79.30% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unintuitive almost white color when plotting with datashader

2 participants