Repository navigation
Public Prism axis-length helpers: add_axes_inches, legend_inches, suptitle_inches - #10
Merged
Merged
Conversation
Public helpers for Prism-style layouts in inches: - add_axes_inches(fig, left, bottom, width, height) places axes whose x- and y-axis lengths are given in inches. An axes locator keeps the position and size when the figure is resized and at any dpi. - legend_inches(ax, x, y, loc) puts the legend's loc point at (x, y) inches. - suptitle_inches(fig, t, top) puts a centered figure title's top edge top inches below the figure's top edge. The example scripts use them instead of their own copies; examples/_common.py keeps only the Arial check and save(). README documents the feature and AGENTS.md points the rendering rules at mplplots.utils. The regenerated example images are byte-identical.
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.
Summary
Moves the round-inch layout helpers from
examples/_common.pyintomplplots.utilsas public API, so figures can be laid out the way GraphPad Prism does: by axis length in inches.add_axes_inches(fig, left, bottom, width, height, **kwargs)adds axes whose x-axis iswidthand y-axisheightinches long, meeting at (left,bottom) inches from the figure's lower-left corner. Unlike plain figure fractions, an axes locator keeps the position and size when the figure is resized and at any dpi. Non-positive sizes raiseValueError.legend_inches(ax, x, y, loc="upper left", **kwargs)puts the legend point thatlocnames (a corner, an edge midpoint, or the center) at (x, y) inches; other options go toax.legend.suptitle_inches(fig, t, top=0.1, **kwargs)adds a centered figure title whose top edge istopinches below the figure's top edge.LegendCorneris theLiteraltype of the ninelocvalues.The example scripts use these instead of their own copies;
examples/_common.pykeeps only the Arial check andsave(). README gains an "Axis lengths in inches" section with a runnable example, and AGENTS.md's rendering rules point atmplplots.utils.Because the locator fixes the axes,
tight_layout, constrained layout,ax.set_positionandfig.colorbar(..., ax=ax)do not move them; the docstring and README say to give a colorbar its ownadd_axes_inchesaxes and pass it ascax.Test plan
fig.set_size_inches(a fraction-only control drifts to 0.833, 0.711, 4.583, 3.378 in), pixel position in a saved PNG,ValueErrorfor empty axes, legend corner at the point for threelocvalues and after a resize, options passed toax.legend, title top edge and centering after a resize.main.pre-commit run --all-filespytest(298 passed), also locally with Matplotlib 3.8.0 / NumPy 1.26.4.