Skip to content

Fix restoring 'auto' aspect in 3D axes after switching from 'equal'#31304

Open
jayaprajapatii wants to merge 1 commit intomatplotlib:mainfrom
jayaprajapatii:fix-3dplot-aspect-back-to-auto
Open

Fix restoring 'auto' aspect in 3D axes after switching from 'equal'#31304
jayaprajapatii wants to merge 1 commit intomatplotlib:mainfrom
jayaprajapatii:fix-3dplot-aspect-back-to-auto

Conversation

@jayaprajapatii
Copy link
Contributor

Closes #31276

Switching the aspect of a 3D axis from "auto" to "equal" and then back to "auto" did not restore the original plot correctly. The logic for handling "auto" continued executing the equal-aspect adjustments, which modified the axis limits and box aspect.

This change ensures that when aspect == "auto", the box aspect is reset and the function exits early, preventing further equal-aspect logic from running.

The baseline image for test_aspects has been updated to reflect the corrected rendering.

@rcomer
Copy link
Member

rcomer commented Mar 14, 2026

I'm not too familiar with 3D plotting, but the test explicitly set the box aspect. If a user did similarly, shouldn't we respect it?

ax.set_box_aspect((3, 4, 5))
ax.set_aspect(aspects[i], adjustable='datalim')

@jayaprajapatii
Copy link
Contributor Author

Thanks @rcomer
My intention with the early return was to avoid the equal-aspect adjustment logic from running when aspect="auto", since it was continuing to modify the axis limits and box aspect.
You're right that the test explicitly sets a box aspect. In that case we should respect a user-defined set_box_aspect.

Would it make more sense to only reset the box aspect when it was implicitly modified by the equal-aspect logic, rather than when it was explicitly set by the user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Setting aspect back to auto cannot recover the original 3D plot

2 participants