Fix outer legend hiding y-tick labels with sharey='labs' (#694)#696
Merged
cvanelteren merged 1 commit intomainfrom Apr 16, 2026
Merged
Fix outer legend hiding y-tick labels with sharey='labs' (#694)#696cvanelteren merged 1 commit intomainfrom
cvanelteren merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #694.
Summary
_effective_share_level(infigure.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 turnedlabelleftoff 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=Trueor_panel_share=False, matching the same predicate_apply_auto_sharealready 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:test_outer_legend_keeps_ticklabels_with_label_sharing[labs|lims]— the issue Adding a legend to right of plot can remove y-axis tick labels #694 reproducer.test_outer_legend_preserves_share_true_ticklabel_hiding— guard so the fix doesn't accidentally re-enable interior tick labels whensharey=True(level 3).All 455 pre-existing
test_subplots/test_figure/test_axes/test_colorbartests 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 systems —
cartesian.py:_apply_axis_sharing_for_axis(per-axes) andfigure.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:
_panel_participates_in_sharing(p)predicate used by every site that filters panel lists.cartesian.py:505,cartesian.py:820/847,figure.py:_effective_share_level).This aligns with the existing plan to extract layout/sharing logic out of
Figure. I'll open a separate tracking issue for it.