From 5f03c958f22e2ccbde34ad804b236b3cdefd1130 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Mon, 9 Nov 2015 11:07:55 -0500 Subject: [PATCH 01/14] added axes reset to normal order (+x up, +y up) --- lib/matplotlib/axes/_base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index bf44d1176cc7..a771ccffed36 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -997,6 +997,7 @@ def cla(self): self.xaxis.set_minor_locator(minl) else: self.xaxis._set_scale('linear') + self.viewLim.intervalx = (0, 1) if self._sharey is not None: self.yaxis.major = self._sharey.yaxis.major @@ -1020,6 +1021,7 @@ def cla(self): self.yaxis.set_minor_locator(minl) else: self.yaxis._set_scale('linear') + self.viewLim.intervaly = (0, 1) # update the minor locator for x and y axis based on rcParams if (rcParams['xtick.minor.visible']): @@ -1110,6 +1112,7 @@ def cla(self): if self._sharey: self.yaxis.set_visible(yaxis_visible) self.patch.set_visible(patch_visible) + self.stale = True @cbook.deprecated("2.1", alternative="Axes.patch") From 76bdae4bfebdc0a5fbcdc0c57c823bc89cb0a243 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Wed, 23 Dec 2015 15:48:00 -0500 Subject: [PATCH 02/14] changed to use set_xlim instead, also added tests --- lib/matplotlib/axes/_base.py | 6 +++-- lib/matplotlib/tests/test_axes.py | 42 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index a771ccffed36..a37d910acc5a 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -997,7 +997,8 @@ def cla(self): self.xaxis.set_minor_locator(minl) else: self.xaxis._set_scale('linear') - self.viewLim.intervalx = (0, 1) + #self.viewLim.intervalx = (0, 1) + self.set_xlim(0,1) if self._sharey is not None: self.yaxis.major = self._sharey.yaxis.major @@ -1021,7 +1022,8 @@ def cla(self): self.yaxis.set_minor_locator(minl) else: self.yaxis._set_scale('linear') - self.viewLim.intervaly = (0, 1) + #self.viewLim.intervaly = (0, 1) + self.set_ylim(0,1) # update the minor locator for x and y axis based on rcParams if (rcParams['xtick.minor.visible']): diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 39dea8698af4..b08db1ddc1b7 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -177,6 +177,48 @@ def test_twin_inherit_autoscale_setting(): assert ax_y_on.get_autoscaley_on() assert not ax_y_off.get_autoscaley_on() +@cleanup +def test_inverted_cla(): + # Github PR #5450. Setting autoscale should reset + # axes to be non-inverted. + # plotting an image, then 1d graph, axis is now down + fig = plt.figure(0); + ax = fig.gca() + # test that a new axis is not inverted per default + assert not(ax.xaxis_inverted()) + assert not(ax.yaxis_inverted()) + img = np.random.random((100,100)) + ax.imshow(img) + # test that a image axis is inverted + assert not(ax.xaxis_inverted()) + assert ax.yaxis_inverted() + ax.cla() + x = np.linspace(0,2*np.pi,100); + ax.plot(x,np.cos(x)) + assert not(ax.xaxis_inverted()) + assert not(ax.yaxis_inverted()) + + # autoscaling should not bring back axes to normal + ax.cla() + ax.imshow(img) + plt.autoscale() + assert not(ax.xaxis_inverted()) + assert ax.yaxis_inverted() + + # two shared axes. Clearing the master axis should bring axes in shared + # axies back to normal + ax0 = plt.subplot(211) + ax1 = plt.subplot(212, sharey=ax0) + ax0.imshow(img) + ax1.plot(x,np.cos(x)) + ax0.cla() + assert not(ax1.yaxis_inverted()) + ax1.cla() + # clearing the nonmaster should not touch limits + ax0.imshow(img) + ax1.plot(x,np.cos(x)) + ax1.cla() + assert ax.yaxis_inverted() @image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png']) From 479d68f73f4434736e1288453e42ad13674465bc Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Wed, 23 Dec 2015 17:27:51 -0500 Subject: [PATCH 03/14] PEP8 fix and removed two comments --- lib/matplotlib/axes/_base.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index a37d910acc5a..24afee7f831b 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -997,8 +997,7 @@ def cla(self): self.xaxis.set_minor_locator(minl) else: self.xaxis._set_scale('linear') - #self.viewLim.intervalx = (0, 1) - self.set_xlim(0,1) + self.set_xlim(0, 1) if self._sharey is not None: self.yaxis.major = self._sharey.yaxis.major @@ -1022,8 +1021,7 @@ def cla(self): self.yaxis.set_minor_locator(minl) else: self.yaxis._set_scale('linear') - #self.viewLim.intervaly = (0, 1) - self.set_ylim(0,1) + self.set_ylim(0, 1) # update the minor locator for x and y axis based on rcParams if (rcParams['xtick.minor.visible']): From 917de33fa92a4923f4bd340fbbb14d19546312b1 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Thu, 24 Dec 2015 00:04:40 -0500 Subject: [PATCH 04/14] added TypeError exception handling to setting x/ylim --- lib/matplotlib/axes/_base.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 24afee7f831b..5cb4f5443173 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -997,7 +997,10 @@ def cla(self): self.xaxis.set_minor_locator(minl) else: self.xaxis._set_scale('linear') - self.set_xlim(0, 1) + try: + self.set_xlim(0, 1) + except TypeError: + pass if self._sharey is not None: self.yaxis.major = self._sharey.yaxis.major @@ -1021,7 +1024,10 @@ def cla(self): self.yaxis.set_minor_locator(minl) else: self.yaxis._set_scale('linear') - self.set_ylim(0, 1) + try: + self.set_ylim(0, 1) + except TypeError: + pass # update the minor locator for x and y axis based on rcParams if (rcParams['xtick.minor.visible']): From ab0d228ce377d3874b7456ab5874642d376627fc Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Thu, 24 Dec 2015 10:57:11 -0500 Subject: [PATCH 05/14] PEP8 fixes to test_axes.py --- lib/matplotlib/tests/test_axes.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b08db1ddc1b7..dfa34b4b1cce 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -177,24 +177,25 @@ def test_twin_inherit_autoscale_setting(): assert ax_y_on.get_autoscaley_on() assert not ax_y_off.get_autoscaley_on() + @cleanup def test_inverted_cla(): - # Github PR #5450. Setting autoscale should reset + # Github PR #5450. Setting autoscale should reset # axes to be non-inverted. # plotting an image, then 1d graph, axis is now down - fig = plt.figure(0); + fig = plt.figure(0) ax = fig.gca() # test that a new axis is not inverted per default assert not(ax.xaxis_inverted()) assert not(ax.yaxis_inverted()) - img = np.random.random((100,100)) + img = np.random.random((100, 100)) ax.imshow(img) # test that a image axis is inverted assert not(ax.xaxis_inverted()) assert ax.yaxis_inverted() ax.cla() - x = np.linspace(0,2*np.pi,100); - ax.plot(x,np.cos(x)) + x = np.linspace(0, 2*np.pi, 100) + ax.plot(x, np.cos(x)) assert not(ax.xaxis_inverted()) assert not(ax.yaxis_inverted()) @@ -210,13 +211,13 @@ def test_inverted_cla(): ax0 = plt.subplot(211) ax1 = plt.subplot(212, sharey=ax0) ax0.imshow(img) - ax1.plot(x,np.cos(x)) + ax1.plot(x, np.cos(x)) ax0.cla() assert not(ax1.yaxis_inverted()) ax1.cla() # clearing the nonmaster should not touch limits ax0.imshow(img) - ax1.plot(x,np.cos(x)) + ax1.plot(x, np.cos(x)) ax1.cla() assert ax.yaxis_inverted() @@ -2148,6 +2149,7 @@ def test_boxplot_autorange_whiskers(): ax2.set_ylim((-5, 5)) + def _rc_test_bxp_helper(ax, rc_dict): x = np.linspace(-7, 7, 140) x = np.hstack([-25, x, 25]) From 8c47c5522a175e986288c0678068d76f2abb0055 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Fri, 25 Dec 2015 11:26:25 -0500 Subject: [PATCH 06/14] removed a trailing whitespace --- lib/matplotlib/tests/test_axes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index dfa34b4b1cce..d40eba12df23 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -185,28 +185,30 @@ def test_inverted_cla(): # plotting an image, then 1d graph, axis is now down fig = plt.figure(0) ax = fig.gca() - # test that a new axis is not inverted per default + # 1. test that a new axis is not inverted per default assert not(ax.xaxis_inverted()) assert not(ax.yaxis_inverted()) img = np.random.random((100, 100)) ax.imshow(img) - # test that a image axis is inverted + # 2. test that a image axis is inverted assert not(ax.xaxis_inverted()) assert ax.yaxis_inverted() + # 3. test that clearing and plotting a line, axes are + # not inverted ax.cla() x = np.linspace(0, 2*np.pi, 100) ax.plot(x, np.cos(x)) assert not(ax.xaxis_inverted()) assert not(ax.yaxis_inverted()) - # autoscaling should not bring back axes to normal + # 4. autoscaling should not bring back axes to normal ax.cla() ax.imshow(img) plt.autoscale() assert not(ax.xaxis_inverted()) assert ax.yaxis_inverted() - # two shared axes. Clearing the master axis should bring axes in shared + # 5. two shared axes. Clearing the master axis should bring axes in shared # axies back to normal ax0 = plt.subplot(211) ax1 = plt.subplot(212, sharey=ax0) @@ -215,7 +217,7 @@ def test_inverted_cla(): ax0.cla() assert not(ax1.yaxis_inverted()) ax1.cla() - # clearing the nonmaster should not touch limits + # 6. clearing the nonmaster should not touch limits ax0.imshow(img) ax1.plot(x, np.cos(x)) ax1.cla() From 234695f226390a6f5aab1362b7ff20e13bcf83c4 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Sun, 9 Apr 2017 19:04:25 -0400 Subject: [PATCH 07/14] added same change to axes3D --- lib/mpl_toolkits/mplot3d/axes3d.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 2b44de576dc0..bd28ed8f3c6b 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1086,6 +1086,10 @@ def cla(self): self.zaxis._set_scale(self._sharez.zaxis.get_scale()) else: self.zaxis._set_scale('linear') + try: + self.set_zlim(0, 1) + except TypeError: + pass self._autoscaleZon = True self._zmargin = 0 From 76b802dd31c7978977b2fd3ba18d54baf3d1fb79 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Sun, 9 Apr 2017 19:36:27 -0400 Subject: [PATCH 08/14] changed figure cleanup --- lib/matplotlib/tests/test_axes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d40eba12df23..9011dea0b1ba 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -178,7 +178,6 @@ def test_twin_inherit_autoscale_setting(): assert not ax_y_off.get_autoscaley_on() -@cleanup def test_inverted_cla(): # Github PR #5450. Setting autoscale should reset # axes to be non-inverted. @@ -223,6 +222,9 @@ def test_inverted_cla(): ax1.cla() assert ax.yaxis_inverted() + # clean up + plt.close(fig) + @image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png']) def test_minorticks_on_rcParams_both(): From 01ebc98af5fd3f9190f6779b5a4103c81cd9722c Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Sun, 9 Apr 2017 19:44:34 -0400 Subject: [PATCH 09/14] Also pass on AttributeError --- lib/mpl_toolkits/mplot3d/axes3d.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index bd28ed8f3c6b..3e1012cbaf03 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1090,6 +1090,8 @@ def cla(self): self.set_zlim(0, 1) except TypeError: pass + except AttributeError: + pass self._autoscaleZon = True self._zmargin = 0 From 64f80e6e1cbfa7793824e500645689ffd1adb216 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Sun, 9 Apr 2017 19:57:52 -0400 Subject: [PATCH 10/14] added tests --- lib/matplotlib/tests/test_axes.py | 2 +- lib/mpl_toolkits/tests/test_mplot3d.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 9011dea0b1ba..d012af015150 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -208,7 +208,7 @@ def test_inverted_cla(): assert ax.yaxis_inverted() # 5. two shared axes. Clearing the master axis should bring axes in shared - # axies back to normal + # axes back to normal ax0 = plt.subplot(211) ax1 = plt.subplot(212, sharey=ax0) ax0.imshow(img) diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 7ba561c6d866..10296866e76a 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -564,3 +564,23 @@ def test_invalid_axes_limits(setter, side, value): obj = fig.add_subplot(111, projection='3d') with pytest.raises(ValueError): getattr(obj, setter)(**limit) + + +def test_inverted_cla(): + # Github PR #5450. Setting autoscale should reset + # axes to be non-inverted. + fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) + # 1. test that a new axis is not inverted per default + assert not ax.xaxis_inverted() + assert not ax.yaxis_inverted() + assert not ax.zaxis_inverted() + ax.set_xlim(1, 0) + ax.set_ylim(1, 0) + ax.set_zlim(1, 0) + assert ax.xaxis_inverted() + assert ax.yaxis_inverted() + assert ax.zaxis_inverted() + ax.cla() + assert not ax.xaxis_inverted() + assert not ax.yaxis_inverted() + assert not ax.zaxis_inverted() From ab310ec495e4509d20b6844e318499cf1bb7a119 Mon Sep 17 00:00:00 2001 From: Julien Lhermitte Date: Sun, 9 Apr 2017 22:38:57 -0400 Subject: [PATCH 11/14] PEP8 fix (for Travis CI) --- lib/matplotlib/tests/test_axes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d012af015150..0e2a54940281 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2153,7 +2153,6 @@ def test_boxplot_autorange_whiskers(): ax2.set_ylim((-5, 5)) - def _rc_test_bxp_helper(ax, rc_dict): x = np.linspace(-7, 7, 140) x = np.hstack([-25, x, 25]) From e425eafebeb2ae41c329f286328b7d4557babfd7 Mon Sep 17 00:00:00 2001 From: Julien L Date: Tue, 11 Apr 2017 09:49:43 -0400 Subject: [PATCH 12/14] another PEP8 fix for Travis CI --- lib/matplotlib/tests/test_axes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 0e2a54940281..49b6a57e67ac 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -225,6 +225,7 @@ def test_inverted_cla(): # clean up plt.close(fig) + @image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png']) def test_minorticks_on_rcParams_both(): From 1ae6d9e8b68099a198cf0f000bfbe715a632a768 Mon Sep 17 00:00:00 2001 From: Julien L Date: Wed, 12 Apr 2017 09:48:26 -0400 Subject: [PATCH 13/14] moved Axes2D cla to top of Axes3D cla --- lib/mpl_toolkits/mplot3d/axes3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 3e1012cbaf03..4c60f7df1b65 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1076,6 +1076,7 @@ def cla(self): # Disabling mouse interaction might have been needed a long # time ago, but I can't find a reason for it now - BVR (2012-03) #self.disable_mouse_rotation() + Axes.cla(self) self.zaxis.cla() if self._sharez is not None: @@ -1096,7 +1097,6 @@ def cla(self): self._autoscaleZon = True self._zmargin = 0 - Axes.cla(self) self.grid(rcParams['axes3d.grid']) From a2f7ed9d67fd9251c08215d7b4a826ce7c43b36e Mon Sep 17 00:00:00 2001 From: Julien L Date: Wed, 12 Apr 2017 09:54:17 -0400 Subject: [PATCH 14/14] raise AttributeError exception for set_zlim --- lib/mpl_toolkits/mplot3d/axes3d.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 4c60f7df1b65..f7156e07f015 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1091,8 +1091,6 @@ def cla(self): self.set_zlim(0, 1) except TypeError: pass - except AttributeError: - pass self._autoscaleZon = True self._zmargin = 0