Skip to content

Public Prism axis-length helpers: add_axes_inches, legend_inches, suptitle_inches - #10

Merged
FridrichMethod merged 1 commit into
mainfrom
feat/utils-axis-lengths
Nov 17, 2026
Merged

FridrichMethod merged 1 commit into
mainfrom
feat/utils-axis-lengths

Conversation

@FridrichMethod

Copy link
Copy Markdown
Owner

Summary

Moves the round-inch layout helpers from examples/_common.py into mplplots.utils as 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 is width and y-axis height inches 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 raise ValueError.
  • legend_inches(ax, x, y, loc="upper left", **kwargs) puts the legend point that loc names (a corner, an edge midpoint, or the center) at (x, y) inches; other options go to ax.legend.
  • suptitle_inches(fig, t, top=0.1, **kwargs) adds a centered figure title whose top edge is top inches below the figure's top edge.
  • LegendCorner is the Literal type of the nine loc values.

The example scripts use these instead of their own copies; examples/_common.py keeps only the Arial check and save(). README gains an "Axis lengths in inches" section with a runnable example, and AGENTS.md's rendering rules point at mplplots.utils.

Because the locator fixes the axes, tight_layout, constrained layout, ax.set_position and fig.colorbar(..., ax=ax) do not move them; the docstring and README say to give a colorbar its own add_axes_inches axes and pass it as cax.

Test plan

  • 11 new tests: axes extents in inches (default and GraphPadPrism styles), axis lengths unchanged after 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, ValueError for empty axes, legend corner at the point for three loc values and after a resize, options passed to ax.legend, title top edge and centering after a resize.
  • Re-rendering both example scripts with the library helpers gives all 42 files byte-identical to main.
  • The README example runs and writes a 216 × 162 pt (3 × 2.25 in) PDF.
  • pre-commit run --all-files
  • pytest (298 passed), also locally with Matplotlib 3.8.0 / NumPy 1.26.4.

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.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 02:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@FridrichMethod
FridrichMethod merged commit ed2ae78 into main Nov 17, 2026
3 checks passed
@FridrichMethod
FridrichMethod deleted the feat/utils-axis-lengths branch November 17, 2026 02:09
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.

2 participants