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

Skip to content

Commit 6ab7b18

Browse files
committed
axis() preserves autoscaling state unless axis limits are set.
Closes sourceforge bug 3165439. I also fixed an inconsistency in the handling of the emit kwarg, and made the autoscaling handling more explicit.
1 parent 7e54ffb commit 6ab7b18

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/matplotlib/axes.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,24 +1273,31 @@ def axis(self, *v, **kwargs):
12731273
ymin, ymax = self.get_ylim()
12741274
return xmin, xmax, ymin, ymax
12751275

1276-
try: v[0]
1276+
emit = kwargs.get('emit', True)
1277+
try:
1278+
v[0]
12771279
except IndexError:
1278-
emit = kwargs.get('emit', True)
12791280
xmin = kwargs.get('xmin', None)
12801281
xmax = kwargs.get('xmax', None)
1282+
auto = False # turn off autoscaling, unless...
1283+
if xmin is None and xmax is None:
1284+
auto = None # leave autoscaling state alone
1285+
xmin, xmax = self.set_xlim(xmin, xmax, emit=emit, auto=auto)
12811286

1282-
xmin, xmax = self.set_xlim(xmin, xmax, emit)
12831287
ymin = kwargs.get('ymin', None)
12841288
ymax = kwargs.get('ymax', None)
1285-
ymin, ymax = self.set_ylim(ymin, ymax, emit)
1289+
auto = False # turn off autoscaling, unless...
1290+
if ymin is None and ymax is None:
1291+
auto = None # leave autoscaling state alone
1292+
ymin, ymax = self.set_ylim(ymin, ymax, emit=emit, auto=auto)
12861293
return xmin, xmax, ymin, ymax
12871294

12881295
v = v[0]
12891296
if len(v) != 4:
12901297
raise ValueError('v must contain [xmin xmax ymin ymax]')
12911298

1292-
self.set_xlim([v[0], v[1]])
1293-
self.set_ylim([v[2], v[3]])
1299+
self.set_xlim([v[0], v[1]], emit=emit, auto=False)
1300+
self.set_ylim([v[2], v[3]], emit=emit, auto=False)
12941301

12951302
return v
12961303

0 commit comments

Comments
 (0)