Repository navigation
Fit the legend and title hypertools adds to a caller's axes (1.1.1) - #294
Merged
Merged
Conversation
A legend beside a caller-supplied axes ran off the canvas or over the next panel until the caller laid the figure out, and a 3-D legend stayed clipped even after the caller's tight_layout. An axes locator now narrows only that axes, at draw time and inside the room the caller's layout gave it, until its legend and title fit; the figure's size, engine and other axes are untouched. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DcKtysUSGLqA8RApYP9xYG
Recompute the fit on every draw (no memo), answer layout passes with the unfitted position, make twins follow, treat colorbars and visible neighbor labels as limits, keep titles on their side, restore an inside legend when room appears, and report legends that cannot be seated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DcKtysUSGLqA8RApYP9xYG
Restore data limits around the search, report legends that run over rows, cut the per-draw cost, measure layouts with the legend outside, follow twins made later, leave a restyled legend to the caller, recognize layout passes by module, and read neighbor labels where the next draw puts them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DcKtysUSGLqA8RApYP9xYG
Check the legend's vertical room on the final box, fit titles on twins, release a twin whose leader was removed, and treat a recolored inside legend as the caller's. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DcKtysUSGLqA8RApYP9xYG
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DcKtysUSGLqA8RApYP9xYG
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.
Follow-up to #293, for the same unreleased 1.1.1.
What this changes
After #293,
hyp.plot(..., ax=ax)no longer lays out or resizes a figure the caller built. That left the legend hypertools hangs off the right ofaxrunning off the canvas, or over the next panel, until the caller laid the figure out; a 3-D legend stayed clipped even after the caller's ownfig.tight_layout().hyp.plotnow installs a matplotlib axes locator (_CallerSlotLocator) on a caller-supplied axes that carries a legend or a title. When the figure is drawn it narrows that axes from the right until its legend ends before the canvas edge or the next panel (its visible tick and axis labels, or a colorbar, included), and lowers it until its title is on the canvas. The figure's size, its layout engine and the slot of every other axes are not changed.tight_layout,subplots_adjust, a resize, a save at another dpi, or an edit to the legend.tight_layoutor a layout engine is measuring, the locator answers with the unfitted position (and the legend outside), so slots are identical, draw for draw, to the same figure without the locator.UserWarning.Figures hypertools creates itself (plain
hyp.plot,hyp.subplots,panels=) are unchanged: pixel-identical to master in three independent checks.Measurements
tight_layoutin 3-D. After: none.Not covered
ax.get_position()reports the position of the last draw.Review and tests
Three review rounds (Codex CLI each round, a fresh subagent in rounds 1 and 2); every confirmed finding has a regression test.
tests/test_caller_figure_hygiene.pynow has 100 tests and passes on matplotlib 3.10.8 and 3.11.2. Full suite: 6904 passed, 1 failed (missing docstrings on the new helpers, fixed in the last commit and re-run with the 24 test files that draw into caller axes). Sphinx-Wbuild with every gallery example re-executed succeeded. Session log:notes/session_2026-11-21_release-1.1.1.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01DcKtysUSGLqA8RApYP9xYG