Skip to content

FIX: include axis labels in get_tightbbox when not for_layout_only - #31932

Merged
scottshambaugh merged 1 commit into
matplotlib:mainfrom
rcomer:fix/axes3d-tightbbox-labels
Jun 30, 2026
Merged

FIX: include axis labels in get_tightbbox when not for_layout_only#31932
scottshambaugh merged 1 commit into
matplotlib:mainfrom
rcomer:fix/axes3d-tightbbox-labels

Conversation

@rcomer

@rcomer rcomer commented Jun 20, 2026

Copy link
Copy Markdown
Member

PR summary

Fixes #28117 and fixes #31568

This is the rebased branch from #31571, with some modifications for the 3D case and an added fix for the standard axes case. Since 5c75807 we have not been passing for_layout_only=False from the axes get_tightbbox down to the axis get_tightbbox. This PR makes sure that we do by explicitly calling axis.get_tightbbox() for that case, without the keyword in case we have hold of a third party axis that does not support it.

An alternative solution is to modify the _get_tightbbox_for_layout_only helper function, which I tried at #28117 (comment). I'd be happy to switch to that - I don't have an opinion on which is better.

The code from #31568 now gives
3d_tight

The code from #28117 (comment) now gives
test

Note there is also #31573, but I prefer the solution from #31571 because it leaves the responsibility for the axis labels with the relevant axis.

AI Disclosure

No AI used by me.

PR checklist

@rcomer

This comment was marked as outdated.

@rcomer rcomer added the PR: bugfix Pull requests that fix identified bugs label Jun 20, 2026
@rcomer rcomer closed this Jun 23, 2026
@rcomer rcomer reopened this Jun 23, 2026

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this here is the cleaner solution.

@scottshambaugh scottshambaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for tackling this, iirc there were 3 PRs that tried to fix this opened at once and it was a bit of a mess reconciling them. This is a clean approach.

@scottshambaugh scottshambaugh added this to the v3.11.1 milestone Jun 30, 2026
@scottshambaugh
scottshambaugh merged commit c0a08db into matplotlib:main Jun 30, 2026
78 of 82 checks passed
@rcomer
rcomer deleted the fix/axes3d-tightbbox-labels branch June 30, 2026 15:01
QuLogic pushed a commit that referenced this pull request Jun 30, 2026
QuLogic added a commit that referenced this pull request Jun 30, 2026
…932-on-v3.11.x

Backport PR #31932 on branch v3.11.x (FIX: include axis labels in get_tightbbox when not for_layout_only)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bugfix Pull requests that fix identified bugs topic: axes topic: mplot3d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: savefig(bbox_inches='tight') clips axis labels on 3D axes [Bug]: The zlabel on 3D axes will be cut when using '%matplotlib inline' in Jupyter

4 participants