Fix restoring 'auto' aspect in 3D axes after switching from 'equal'#31304
Fix restoring 'auto' aspect in 3D axes after switching from 'equal'#31304jayaprajapatii wants to merge 2 commits intomatplotlib:mainfrom
Conversation
|
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? matplotlib/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py Lines 88 to 89 in 32805b1 |
|
Thanks @rcomer 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? |
|
I think that overriding a previously set aspect with "auto" is the correct behavior. But we should have different behavior with setting "auto" on the "datalim" - the box shouldn't be modified in that case. |
scottshambaugh
left a comment
There was a problem hiding this comment.
The test image was changed in separate commits, so that needs to be git squashed or rebased to fix the "PR Cleanliness" failure.
Also, this new behavior needs to be tested.
e8db81d to
a4d63fa
Compare
scottshambaugh
left a comment
There was a problem hiding this comment.
Ok, I think this is looking good for the adjustable='box' case. What's the current behavior for 'datalim'? That should be fixed at the same time as well.
| initial_limits = ax.get_w_lims() | ||
|
|
||
| ax.set_aspect("equal") | ||
| fig.canvas.draw() |
There was a problem hiding this comment.
Please add assert not np.allclose(initial_limits, new_limits) here to ensure the limits do actually change.
|
Hello @scottshambaugh Updated I verified that in the |
|
What is the current behavior for 'datalim'? Please share screenshots, and try to set up a case where this is exercised. I don't think the test added for the datalim case is meaningfully doing anything right now. |


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_aspectshas been updated to reflect the corrected rendering.