You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Hi,
I suggest that if A shares an axis with B, then B should also have his sharex/sharey attribute changed.
The following modification in the lib/matplotlib/axes/_base.py file solves your issue.
diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py
index 12dace5b00..874e30e9e5 100644
--- a/lib/matplotlib/axes/_base.py+++ b/lib/matplotlib/axes/_base.py@@ -1233,8 +1233,8 @@ class _AxesBase(martist.Artist):
x0, x1 = other.get_xlim()
self.set_xlim(x0, x1, emit=False, auto=other.get_autoscalex_on())
self.xaxis._scale = other.xaxis._scale
+ other._shared_axes["x"].join(other, self)+ other._sharex = self
def sharey(self, other):
"""
@@ -1254,8 +1254,8 @@ class _AxesBase(martist.Artist):
y0, y1 = other.get_ylim()
self.set_ylim(y0, y1, emit=False, auto=other.get_autoscaley_on())
self.yaxis._scale = other.yaxis._scale
+ other._shared_axes["y"].join(other, self)+ other._sharey = self
def __clear(self):
"""Clear the Axes."""
@@ -1374,7 +1374,7 @@ class _AxesBase(martist.Artist):
share = getattr(self, f"_share{name}")
if share is not None:
getattr(self, f"share{name}")(share)
+ axis.set_inverted(False)
else:
# Although the scale was set to linear as part of clear,
# polar requires that _set_scale is called again
After running tests , i noticed that we also have to manually invert any inverted axis when clearing a subplot
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 toA.cla()
will not change the xlimit).I think the main problem comes from the following function, where it will check whether its
_sharex
attribute isNone
; however, in this case, B is shared to A, but no axis is shared to B, so B's_sharex
attribute isNone
.matplotlib/lib/matplotlib/axes/_base.py
Line 1369 in 9e18a34
Code for reproduction
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
The text was updated successfully, but these errors were encountered: