Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76bdae4

Browse files
jrmlhermitteJulien L
authored andcommitted
changed to use set_xlim instead, also added tests
1 parent 5f03c95 commit 76bdae4

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,8 @@ def cla(self):
997997
self.xaxis.set_minor_locator(minl)
998998
else:
999999
self.xaxis._set_scale('linear')
1000-
self.viewLim.intervalx = (0, 1)
1000+
#self.viewLim.intervalx = (0, 1)
1001+
self.set_xlim(0,1)
10011002

10021003
if self._sharey is not None:
10031004
self.yaxis.major = self._sharey.yaxis.major
@@ -1021,7 +1022,8 @@ def cla(self):
10211022
self.yaxis.set_minor_locator(minl)
10221023
else:
10231024
self.yaxis._set_scale('linear')
1024-
self.viewLim.intervaly = (0, 1)
1025+
#self.viewLim.intervaly = (0, 1)
1026+
self.set_ylim(0,1)
10251027

10261028
# update the minor locator for x and y axis based on rcParams
10271029
if (rcParams['xtick.minor.visible']):

lib/matplotlib/tests/test_axes.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,48 @@ def test_twin_inherit_autoscale_setting():
177177
assert ax_y_on.get_autoscaley_on()
178178
assert not ax_y_off.get_autoscaley_on()
179179

180+
@cleanup
181+
def test_inverted_cla():
182+
# Github PR #5450. Setting autoscale should reset
183+
# axes to be non-inverted.
184+
# plotting an image, then 1d graph, axis is now down
185+
fig = plt.figure(0);
186+
ax = fig.gca()
187+
# test that a new axis is not inverted per default
188+
assert not(ax.xaxis_inverted())
189+
assert not(ax.yaxis_inverted())
190+
img = np.random.random((100,100))
191+
ax.imshow(img)
192+
# test that a image axis is inverted
193+
assert not(ax.xaxis_inverted())
194+
assert ax.yaxis_inverted()
195+
ax.cla()
196+
x = np.linspace(0,2*np.pi,100);
197+
ax.plot(x,np.cos(x))
198+
assert not(ax.xaxis_inverted())
199+
assert not(ax.yaxis_inverted())
200+
201+
# autoscaling should not bring back axes to normal
202+
ax.cla()
203+
ax.imshow(img)
204+
plt.autoscale()
205+
assert not(ax.xaxis_inverted())
206+
assert ax.yaxis_inverted()
207+
208+
# two shared axes. Clearing the master axis should bring axes in shared
209+
# axies back to normal
210+
ax0 = plt.subplot(211)
211+
ax1 = plt.subplot(212, sharey=ax0)
212+
ax0.imshow(img)
213+
ax1.plot(x,np.cos(x))
214+
ax0.cla()
215+
assert not(ax1.yaxis_inverted())
216+
ax1.cla()
217+
# clearing the nonmaster should not touch limits
218+
ax0.imshow(img)
219+
ax1.plot(x,np.cos(x))
220+
ax1.cla()
221+
assert ax.yaxis_inverted()
180222

181223
@image_comparison(baseline_images=["minorticks_on_rcParams_both"],
182224
extensions=['png'])

0 commit comments

Comments
 (0)