Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Axes.cla() with sharex may wrongly reset the axes limit. #27825

Open
@tianzhuqiao

Description

@tianzhuqiao

Bug summary

For example, when subplot A shares the x-axis with subplot B (A is created with sharex=B), a call to B.cla() will set the xlimit to [0, 1], which may not be expected (in contrast, a call to A.cla() will not change the xlimit).

I think the main problem comes from the following function, where it will check whether its _sharex attribute is None; however, in this case, B is shared to A, but no axis is shared to B, so B's _sharex attribute is None.

if share is not None:

Code for reproduction

ax = plt.subplot(211)
ax2 = plt.subplot(212, sharex=ax)
ax.plot(range(50))
ax2.plot(range(50))
ax.cla()
plt.show()

Actual outcome

image

Expected outcome

image

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.3

Matplotlib Backend

'TkAgg'

Python version

3.9.13

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions