Open
Description
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
.
matplotlib/lib/matplotlib/axes/_base.py
Line 1369 in 9e18a34
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
Expected outcome
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