Skip to content

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

@smith2936

Description

@smith2936

Bug summary

This bug arises when I plot filled contours with 3d projection and auto aspect, and save the figure as '3d-plot1.png'. Then, I set the aspect to 'equal' and back to 'auto', and save the figure as '3d-plot2.png', which is inconsistent with '3d-plot1.png'. However, this bug does not occur in 2d filled contours.

Code for reproduction

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d

fig1 = plt.figure()
ax1 = fig1.add_subplot(projection=None)
X, Y, Z = axes3d.get_test_data()
ax1.contourf(X, Y, Z, cmap="coolwarm")
ax1.set_aspect('auto')
fig1.savefig('2d-plot1.png') # Correct
ax1.set_aspect('equal')
ax1.set_aspect('auto')
fig1.savefig('2d-plot2.png') # Correct (consistent with 2d-plot1.png)

fig2 = plt.figure()
ax2 = fig2.add_subplot(projection='3d')
X, Y, Z = axes3d.get_test_data()
ax2.contourf(X, Y, Z, cmap="coolwarm")
ax2.set_aspect('auto')
fig2.savefig('3d-plot1.png') # Correct
ax2.set_aspect('equal')
ax2.set_aspect('auto')
fig2.savefig('3d-plot2.png') # Wrong (inconsistent with 3d-plot1.png)

Actual outcome

2d-plot1.png

Image

2d-plot2.png

Image

3d-plot1.png

Image

3d-plot2.png

Image

Expected outcome

3d-plot2.png should be the same as 3d-plot1.png.

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.8

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions