From 3fd17270c4519bd0a9d2513863a6dbdd2ce667ea Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 15 Mar 2018 15:19:32 -0400 Subject: [PATCH 1/2] Fix for issue #10062 --- lib/matplotlib/axes/_base.py | 12 ++++++++---- lib/matplotlib/tests/test_axes.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) 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..cfc53563c5f6 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') From 7ad9801a5caac8f2c3ddbe51510cea29771804f3 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 15 Mar 2018 19:02:13 -0400 Subject: [PATCH 2/2] Tests must follow PEP8 as well --- lib/matplotlib/tests/test_axes.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cfc53563c5f6..ebfceca2a97f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5128,16 +5128,16 @@ def test_remove_shared_axes_relim(): def test_shared_axes_autoscale(): - l = np.arange(-80,90,40) - t = np.random.random_sample((l.size,l.size)) + 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) + 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) + 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)