Skip to content

[Bug]: Resetting aspect to auto does not work for axes with twinx #31232

@williamlus

Description

@williamlus

Bug summary

This bug occurs when I create a subplot with twin axes. Setting the aspect of axes from 'auto' to 'equal' works fine, but resetting the aspect back to 'auto' does not work.

Code for reproduction

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot()
ax_twin = ax.twinx() # No bug if I remove this
ax.plot([0, 1, 2], [0, 2, 1])

ax.set_aspect('auto')
plt.savefig('plot1.png')
ax.set_aspect('equal')
plt.savefig('tmp.png') # No bug if I remove this
ax.set_aspect('auto')
plt.savefig('plot2.png') # plot2.png should be the same as plot1.png

Actual outcome

plot1.png

Image

plot2.png

Image

Expected outcome

plot2.png should be the same as 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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions