Skip to content

Fix outer legend hiding y-tick labels with sharey='labs' (#694)#696

Merged
cvanelteren merged 1 commit intomainfrom
hotfix/legend-hiding-ticks
Apr 16, 2026
Merged

Fix outer legend hiding y-tick labels with sharey='labs' (#694)#696
cvanelteren merged 1 commit intomainfrom
hotfix/legend-hiding-ticks

Conversation

@cvanelteren
Copy link
Copy Markdown
Collaborator

Closes #694.

Summary

_effective_share_level (in figure.py) was promoting an axes' effective share level to 3 whenever any adjacent panel had a shared axis — including the hidden filled panel that an outer legend (loc='r') creates. That promotion fired _share_ticklabels, whose border-mask then turned labelleft off on the inner subplot because the inner subplot is not on the figure's left border.

The fix filters the "adjacent panels" clause to ignore panels with _panel_hidden=True or _panel_share=False, matching the same predicate _apply_auto_share already uses (shared(paxs)). With that, sharey='labs' no longer loses its tick labels when an outer legend is added next to a subplot.

Tests

Two new flat tests in ultraplot/tests/test_subplots.py:

All 455 pre-existing test_subplots/test_figure/test_axes/test_colorbar tests still pass.

Note for follow-up — proper architectural fix needed

This PR is intentionally minimal. It papers over a deeper duplication: tick-label visibility is currently decided in two parallel systemscartesian.py:_apply_axis_sharing_for_axis (per-axes) and figure.py:_share_ticklabels (figure-level) — that race during draw. The "panel participates in sharing" concept is encoded with four slightly different filters across _apply_auto_share, the span helpers, the cartesian tick-sharing path, and (until this PR) _effective_share_level. The bug lived in exactly that gap.

A proper follow-up should:

  1. Introduce a single _panel_participates_in_sharing(p) predicate used by every site that filters panel lists.
  2. Centralise the "promote to level 3" logic in one place rather than three (cartesian.py:505, cartesian.py:820/847, figure.py:_effective_share_level).
  3. Pick a single owner of tick-label visibility per draw and remove the overlapping logic from the other path.

This aligns with the existing plan to extract layout/sharing logic out of Figure. I'll open a separate tracking issue for it.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cvanelteren cvanelteren merged commit 78a7f94 into main Apr 16, 2026
19 checks passed
@cvanelteren cvanelteren deleted the hotfix/legend-hiding-ticks branch April 16, 2026 23:28
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.

Adding a legend to right of plot can remove y-axis tick labels

1 participant