FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping#31572
Open
buddy0452004 wants to merge 1 commit intomatplotlib:mainfrom
Open
FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping#31572buddy0452004 wants to merge 1 commit intomatplotlib:mainfrom
buddy0452004 wants to merge 1 commit intomatplotlib:mainfrom
Conversation
Previously, the zlabel (and x/y labels) were excluded from the tightbbox when for_layout_only=True, causing savefig(bbox_inches='tight') to clip them in the saved output. Harmonize 3D axis label bbox handling with 2D axes behavior: include the label bbox but collapse it in the layout direction when for_layout_only=True. Fixes matplotlib#28117
c0bf5d5 to
464330c
Compare
Contributor
Author
|
The image comparison failure in |
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.
Fixes #28117
Previously, axis labels on 3D axes were excluded entirely from the tightbbox when
for_layout_only=True. This causedsavefig(bbox_inches='tight')to clip these labels in the saved output sincebbox_inches='tight'usesget_tightbbox()internally. The inline Jupyter backend (%matplotlib inline) also triggers this path, which is the original report in #28117.Root cause: In
axis3d.py, the label was guarded bynot for_layout_only:Fix: Harmonize with 2D axis behavior (
axis.pylines 1368–1380) always include the label bbox, but collapse it in the irrelevant direction whenfor_layout_only=True.Minimum reproducible example:
Before fix:
zlabelandxlabelare clipped in the saved image. After fix: all labels are fully visible.AI Disclosure
None.
PR checklist