diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 9071e30f7f85..0826dc006391 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1015,7 +1015,8 @@ def cla(self): self.xaxis.major = self._sharex.xaxis.major self.xaxis.minor = self._sharex.xaxis.minor x0, x1 = self._sharex.get_xlim() - self.set_xlim(x0, x1, emit=False, auto=None) + self.set_xlim(x0, x1, emit=False, + auto=self._sharex.get_autoscalex_on()) self.xaxis._scale = mscale.scale_factory( self._sharex.xaxis.get_scale(), self.xaxis) else: @@ -1029,7 +1030,8 @@ def cla(self): self.yaxis.major = self._sharey.yaxis.major self.yaxis.minor = self._sharey.yaxis.minor y0, y1 = self._sharey.get_ylim() - self.set_ylim(y0, y1, emit=False, auto=None) + self.set_ylim(y0, y1, emit=False, + auto=self._sharey.get_autoscaley_on()) self.yaxis._scale = mscale.scale_factory( self._sharey.yaxis.get_scale(), self.yaxis) else: @@ -1045,8 +1047,10 @@ def cla(self): if (rcParams['ytick.minor.visible']): self.yaxis.set_minor_locator(mticker.AutoMinorLocator()) - self._autoscaleXon = True - self._autoscaleYon = True + if self._sharex is None: + self._autoscaleXon = True + if self._sharey is None: + self._autoscaleYon = True self._xmargin = rcParams['axes.xmargin'] self._ymargin = rcParams['axes.ymargin'] self._tight = None diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index abd2b6675b48..ebfceca2a97f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5127,6 +5127,23 @@ def test_remove_shared_axes_relim(): assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim) +def test_shared_axes_autoscale(): + l = np.arange(-80, 90, 40) + t = np.random.random_sample((l.size, l.size)) + + ax1 = plt.subplot(211) + ax1.set_xlim(-1000, 1000) + ax1.set_ylim(-1000, 1000) + ax1.contour(l, l, t) + + ax2 = plt.subplot(212, sharex=ax1, sharey=ax1) + ax2.contour(l, l, t) + assert not ax1.get_autoscalex_on() and not ax2.get_autoscalex_on() + assert not ax1.get_autoscaley_on() and not ax2.get_autoscaley_on() + assert ax1.get_xlim() == ax2.get_xlim() == (-1000, 1000) + assert ax1.get_ylim() == ax2.get_ylim() == (-1000, 1000) + + def test_adjust_numtick_aspect(): fig, ax = plt.subplots() ax.yaxis.get_major_locator().set_params(nbins='auto')