From 943f532018dc4d4e243c75f7d86f30af2ea440e9 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Fri, 9 Aug 2024 15:06:38 +0800 Subject: [PATCH 1/3] Fix issue with shared x-axis resetting when calling cla() on shared axes --- lib/matplotlib/axes/_base.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 2fb9a1e82335..328257d35237 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1234,6 +1234,13 @@ def sharex(self, other): x0, x1 = other.get_xlim() self.set_xlim(x0, x1, emit=False, auto=other.get_autoscalex_on()) self.xaxis._scale = other.xaxis._scale + # Ensure bidirectional sharing + other._shared_axes["x"].join(other, self) + other._sharex = self + + # Handle inversion if axes are inverted + if other.xaxis_inverted(): + self.invert_xaxis() def sharey(self, other): """ @@ -1253,6 +1260,13 @@ def sharey(self, other): y0, y1 = other.get_ylim() self.set_ylim(y0, y1, emit=False, auto=other.get_autoscaley_on()) self.yaxis._scale = other.yaxis._scale + # Ensure bidirectional sharing + other._shared_axes["y"].join(other, self) + other._sharey = self + + # Handle inversion if axes are inverted + if other.yaxis_inverted(): + self.invert_yaxis() def __clear(self): """Clear the Axes.""" @@ -1380,6 +1394,12 @@ def __clear(self): self._update_transScale() self.stale = True + # handle shared axis inversion after clear + if self._sharex and self._sharex.xaxis_inverted(): + self.invert_xaxis() + + if self._sharey and self._sharey.yaxis_inverted(): + self.invert_yaxis() def clear(self): """Clear the Axes.""" From 87321cc539d83db536ebe39574b02673659fedba Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Fri, 9 Aug 2024 19:39:20 +0800 Subject: [PATCH 2/3] Fix issue with shared x-axis resetting when calling cla() on shared axes --- lib/matplotlib/axes/_base.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 328257d35237..4057b7e8cd8e 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1238,10 +1238,6 @@ def sharex(self, other): other._shared_axes["x"].join(other, self) other._sharex = self - # Handle inversion if axes are inverted - if other.xaxis_inverted(): - self.invert_xaxis() - def sharey(self, other): """ Share the y-axis with *other*. @@ -1264,10 +1260,6 @@ def sharey(self, other): other._shared_axes["y"].join(other, self) other._sharey = self - # Handle inversion if axes are inverted - if other.yaxis_inverted(): - self.invert_yaxis() - def __clear(self): """Clear the Axes.""" # The actual implementation of clear() as long as clear() has to be @@ -1394,12 +1386,6 @@ def __clear(self): self._update_transScale() self.stale = True - # handle shared axis inversion after clear - if self._sharex and self._sharex.xaxis_inverted(): - self.invert_xaxis() - - if self._sharey and self._sharey.yaxis_inverted(): - self.invert_yaxis() def clear(self): """Clear the Axes.""" From ceeebe8aa9db26e62f3d9878bdaa9a5f2ec6e114 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Fri, 9 Aug 2024 20:22:29 +0800 Subject: [PATCH 3/3] Fix issue with shared x-axis resetting when calling cla() on shared axes --- lib/matplotlib/axes/_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 4057b7e8cd8e..bca10b154cff 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1377,6 +1377,7 @@ def __clear(self): 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