diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e5175ea8761c..535b5cfe1c7a 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -897,7 +897,7 @@ def _request_autoscale_view(self, axis="all", tight=None): Mark a single axis, or all of them, as stale wrt. autoscaling. No computation is performed until the next autoscaling; thus, separate - calls to control individual `Axis`s incur negligible performance cost. + calls to control individual `Axis`'s incur negligible performance cost. Parameters ---------- @@ -1314,8 +1314,9 @@ def __clear(self): xaxis_visible = self.xaxis.get_visible() yaxis_visible = self.yaxis.get_visible() - for axis in self._axis_map.values(): - axis.clear() # Also resets the scale to linear. + for name, axis in self._axis_map.items(): + if self._shared_axes[name].get_siblings(self) == [self]: + axis.clear() # Also resets the scale to linear. for spine in self.spines.values(): spine._clear() # Use _clear to not clear Axis again @@ -1420,6 +1421,9 @@ def __clear(self): share = getattr(self, f"_share{name}") if share is not None: getattr(self, f"share{name}")(share) + elif self in self._shared_axes[name]: + # Do not mess with limits of shared axes. + continue else: # Although the scale was set to linear as part of clear, # polar requires that _set_scale is called again @@ -2185,9 +2189,9 @@ def axis(self, arg=None, /, *, emit=True, **kwargs): xlim = self.get_xlim() ylim = self.get_ylim() edge_size = max(np.diff(xlim), np.diff(ylim))[0] - self.set_xlim(xlim[0], xlim[0] + edge_size, + self.set_xlim([xlim[0], xlim[0] + edge_size], emit=emit, auto=False) - self.set_ylim(ylim[0], ylim[0] + edge_size, + self.set_ylim([ylim[0], ylim[0] + edge_size], emit=emit, auto=False) else: raise ValueError(f"Unrecognized string {arg!r} to axis; "