Skip to content

fix(show): resolve axes/panels mismatch for multi-CS elements (#749) - #784

Merged
timtreis merged 1 commit into
mainfrom
fix/issue-749
Oct 9, 2026
Merged

timtreis merged 1 commit into
mainfrom
fix/issue-749

Conversation

@timtreis

@timtreis timtreis commented Oct 9, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #749. pl.show(ax=single_ax) raised

ValueError: Mismatch between number of matplotlib axes objects (1) and number of panels (2).

when an element carried transformations to several coordinate systems that render the same elements (e.g. visium's "<cs>" and "<cs>_downscaled_lowres"). filter_by_coordinate_system can't strip the extra transformation (upstream scverse/spatialdata#176), so auto-detection produced one panel per coordinate system and a single user axes no longer matched.

PR #580's strict_cs narrowing doesn't help here: both coordinate systems contain the same element, so neither is filtered. The two panels are redundant — identical content, differing only by a scale transform.

Fix

In _resolve_coordinate_systems, after the existing strict_cs step, deduplicate auto-detected coordinate systems by their renderable-element set when axes are supplied: keep the first of each distinct set so a single axes is satisfied, and emit a UserWarning naming the dropped duplicates and pointing to coordinate_systems=. Genuinely distinct coordinate systems keep more sets than axes and still fall through to the existing mismatch ValueError.

Scoped to the ax-provided, auto-detected path only:

  • This path previously raised, so making it render breaks nothing that worked before (backward compatible, as the reporter requested).
  • The no-ax multi-panel behaviour is untouched.
  • Explicit coordinate_systems= is untouched (cs_was_auto is False).

Tests

Non-visual suite passes locally; the only failures are the known CI-only test_plot_* visual-baseline comparisons. No baseline changes expected (new path exercised only by the non-visual regression tests).

…749)

When an element carries transformations to several coordinate systems that
render the same elements (e.g. visium's "<cs>" and "<cs>_downscaled_lowres";
filter_by_coordinate_system can't strip the extra transform, upstream #176),
auto-detection produced one panel per coordinate system and `show(ax=single_ax)`
raised a "Mismatch between number of matplotlib axes objects and number of
panels" ValueError.

Deduplicate auto-detected coordinate systems by their renderable-element set
when axes are supplied: keep the first of each distinct set so a single axes is
satisfied, and warn naming the dropped duplicates (pointing to
`coordinate_systems=`). Genuinely distinct coordinate systems keep more sets
than axes and still raise the mismatch error. Scoped to the ax-provided,
auto-detected path, so the no-ax multi-panel behaviour is unchanged.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.17%. Comparing base (87beb7f) to head (ab0f3cb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #784      +/-   ##
==========================================
+ Coverage   80.11%   80.17%   +0.05%     
==========================================
  Files          18       18              
  Lines        4869     4882      +13     
  Branches     1081     1085       +4     
==========================================
+ Hits         3901     3914      +13     
  Misses        604      604              
  Partials      364      364              
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/basic.py 83.95% <100.00%> (+0.65%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis
timtreis merged commit 6c8b76d into main Oct 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pl.show() leading to ValueError due to mismatch between number of axes and number of panels

2 participants