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

Skip to content

Commit 1a31a11

Browse files
committed
autoscale_view preserves axis direction (e.g., increasing down).
svn path=/trunk/matplotlib/; revision=2636
1 parent b3efaa5 commit 1a31a11

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ def autoscale_view(self, tight=False, scalex=True, scaley=True):
958958
"""
959959
autoscale the view limits using the data limits. You can
960960
selectively autoscale only a single axis, eg, the xaxis by
961-
setting scaley to False.
961+
setting scaley to False. The autoscaling preserves any
962+
axis direction reversal that has already been done.
962963
"""
963964
# if image data only just use the datalim
964965

@@ -972,10 +973,18 @@ def autoscale_view(self, tight=False, scalex=True, scaley=True):
972973
if scaley: self.set_ylim(self.dataLim.intervaly().get_bounds())
973974
return
974975

975-
locator = self.xaxis.get_major_locator()
976-
if scalex: self.set_xlim(locator.autoscale())
977-
locator = self.yaxis.get_major_locator()
978-
if scaley: self.set_ylim(locator.autoscale())
976+
if scalex:
977+
xl = self.get_xlim()
978+
XL = self.xaxis.get_major_locator().autoscale()
979+
if xl[1] < xl[0]:
980+
XL = XL[::-1]
981+
self.set_xlim(XL)
982+
if scaley:
983+
yl = self.get_ylim()
984+
YL = self.yaxis.get_major_locator().autoscale()
985+
if yl[1] < yl[0]:
986+
YL = YL[::-1]
987+
self.set_ylim(YL)
979988
#### Drawing
980989

981990
def draw(self, renderer=None, inframe=False):

0 commit comments

Comments
 (0)