FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping#31572
FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping#31572buddy0452004 wants to merge 1 commit intomatplotlib:mainfrom
Conversation
c0bf5d5 to
464330c
Compare
|
The image comparison failure in |
| elif self.axis_name == "y": | ||
| if bb.height > 0: | ||
| bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5 | ||
| bb.y1 = bb.y0 + 1.0 |
There was a problem hiding this comment.
I think this is the right idea, but needs generalising. My understanding of the 2D case is that, for the layout engine, we do not want to make extra space in the direction parallel to the axis because if the label is very long you eventually just run out of space on the figure. For 2D the parallel direction is fixed for x and y so the code can explicitly mention width and height. For 3D each of x, y, and z can be in any direction.
|
A note on PR priority: usually we prioritise the first PR opened against an issue. #31571 links the same issue and was opened first but only addresses the case when |
464330c to
48ee5b8
Compare
|
Thanks for the feedback. Updated the fix to use |
|
The only remaining failure is the |
|
Hi @buddy0452004 I'm unclear what you mean about version differences. The new image gets saved out automatically when you run the tests locally. The failure message will display the location of the result image. |
|
Hi @rcomer, thanks for the guidance! I've now added the baseline image generated locally using the result image from the test failure. CI is running please let me know if anything else needs to be addressed. |
|
Hi @rcomer, I generated the baseline image from the local test result, but it was produced with FreeType 2.13.3 while CI uses 2.6.1, causing image differences. Is there a way to generate a CI-compatible baseline, or can the baseline be regenerated by CI itself? |
|
Hmmm, I don't know what to advise about your local test run. You can get the CI-generated image from the Artifacts section at the bottom of he Github Actions summary page However, regardless of the text differences, I don't think tight-layout should be adding quite that much white space. I also can't see anything in your logic that would explain why it adds so much. |
9e821ba to
1f40cca
Compare
|
Updated the fix to collapse the label bbox based on get_rotation() angle instead of hardcoding by axis name, as suggested. This correctly handles all view angles since 3D labels can rotate freely. Will update the baseline image once CI generates the new result artifact. |
You already had something based on |
|
Haha no I was just frustrated trying to sort out the baseline situation and wrote that poorly The rotation based approach was already there from before I just explained it badly in the comment |
Previously, axis labels on 3D axes were excluded from the tightbbox when for_layout_only=True, causing savefig(bbox_inches='tight') and the inline Jupyter backend to clip them in the output. Fix: harmonize with 2D axis behavior by always including the label bbox but collapsing it in the irrelevant direction when for_layout_only is True. Create a new Bbox object instead of mutating in place to avoid corrupting the layout engine. Updated baseline image for test_axes3d_primary_views.
030d227 to
2ad5d7e
Compare
|
Sorry for the messy commit history I was going back and forth trying to figure out why the baseline looked so broken. Turns out the real bug was that I was mutating the |
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