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

Skip to content

Commit cb5cab4

Browse files
committed
Axis.set_view_interval: when updating, respect original orientation
svn path=/branches/v1_0_maint/; revision=8652
1 parent e38440f commit cb5cab4

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2010-08-21 Change Axis.set_view_interval() so that when updating an
2+
existing interval, it respects the orientation of that
3+
interval, and can enlarge but not reduce the interval.
4+
This fixes a bug in which Axis.set_ticks would
5+
change the view limits of an inverted axis. Whether
6+
set_ticks should be affecting the viewLim at all remains
7+
an open question. - EF
8+
19
2010-08-16 Handle NaN's correctly in path analysis routines. Fixes a
210
bug where the best location for a legend was not calculated
311
correctly when the line contains NaNs. - MGD

lib/matplotlib/axis.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,11 +1696,21 @@ def get_view_interval(self):
16961696
return self.axes.viewLim.intervalx
16971697

16981698
def set_view_interval(self, vmin, vmax, ignore=False):
1699+
"""
1700+
If *ignore* is *False*, the order of vmin, vmax
1701+
does not matter; the original axis orientation will
1702+
be preserved.
1703+
"""
16991704
if ignore:
17001705
self.axes.viewLim.intervalx = vmin, vmax
17011706
else:
17021707
Vmin, Vmax = self.get_view_interval()
1703-
self.axes.viewLim.intervalx = min(vmin, Vmin), max(vmax, Vmax)
1708+
if Vmin < Vmax:
1709+
self.axes.viewLim.intervalx = (min(vmin, vmax, Vmin),
1710+
max(vmin, vmax, Vmax))
1711+
else:
1712+
self.axes.viewLim.intervalx = (max(vmin, vmax, Vmin),
1713+
min(vmin, vmax, Vmax))
17041714

17051715
def get_minpos(self):
17061716
return self.axes.dataLim.minposx
@@ -1947,11 +1957,21 @@ def get_view_interval(self):
19471957
return self.axes.viewLim.intervaly
19481958

19491959
def set_view_interval(self, vmin, vmax, ignore=False):
1960+
"""
1961+
If *ignore* is *False*, the order of vmin, vmax
1962+
does not matter; the original axis orientation will
1963+
be preserved.
1964+
"""
19501965
if ignore:
19511966
self.axes.viewLim.intervaly = vmin, vmax
19521967
else:
19531968
Vmin, Vmax = self.get_view_interval()
1954-
self.axes.viewLim.intervaly = min(vmin, Vmin), max(vmax, Vmax)
1969+
if Vmin < Vmax:
1970+
self.axes.viewLim.intervaly = (min(vmin, vmax, Vmin),
1971+
max(vmin, vmax, Vmax))
1972+
else:
1973+
self.axes.viewLim.intervaly = (max(vmin, vmax, Vmin),
1974+
min(vmin, vmax, Vmax))
19551975

19561976
def get_minpos(self):
19571977
return self.axes.dataLim.minposy

0 commit comments

Comments
 (0)