Skip to content

WIP: Fix floating-point precision affecting GridSpec bottom and right#31703

Draft
ayshih wants to merge 1 commit into
matplotlib:mainfrom
ayshih:gridspec_bottom_right
Draft

WIP: Fix floating-point precision affecting GridSpec bottom and right#31703
ayshih wants to merge 1 commit into
matplotlib:mainfrom
ayshih:gridspec_bottom_right

Conversation

@ayshih
Copy link
Copy Markdown
Contributor

@ayshih ayshih commented May 18, 2026

PR summary

Currently, due to floating-point precision, GridSpec has the quirk that the returned bottom and right might not exactly match the parameter-specified bottom and right.

For example, for a single subplot and default parameters, the axes bottom should be 0.11 and the axes top should 0.88, but the axes bottom ends up being off by one floating-point tick:

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.get_position()
Bbox([[0.125, 0.10999999999999999], [0.9, 0.88]])

That's because 0.88 - (0.88 - 0.11) gets computed as 0.10999999999999999 and not 0.11.

This PR forces the GridSpec-returned bottom and right to be the parameter-specified bottom and right:

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.get_position()
Bbox([[0.125, 0.11], [0.9, 0.88]])

AI Disclosure

No AI was used

PR checklist

@github-actions github-actions Bot added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant