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

Skip to content

Commit 5964da2

Browse files
committed
Support autoscaling with shared axes
svn path=/trunk/matplotlib/; revision=6315
1 parent 4d20a2f commit 5964da2

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2008-10-23 Autoscaling is now supported with shared axes - EF
2+
13
2008-10-23 Fixed exception in dviread that happened with Minion - JKS
24

35
2008-10-21 set_xlim, ylim now return a copy of the viewlim array to

lib/matplotlib/axes.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,20 +1451,30 @@ def autoscale_view(self, tight=False, scalex=True, scaley=True):
14511451
"""
14521452
# if image data only just use the datalim
14531453
if not self._autoscaleon: return
1454+
if scalex:
1455+
xshared = self._shared_x_axes.get_siblings(self)
1456+
dl = [ax.dataLim for ax in xshared]
1457+
bb = mtransforms.BboxBase.union(dl)
1458+
x0, x1 = bb.intervalx
1459+
if scaley:
1460+
yshared = self._shared_y_axes.get_siblings(self)
1461+
dl = [ax.dataLim for ax in yshared]
1462+
bb = mtransforms.BboxBase.union(dl)
1463+
y0, y1 = bb.intervaly
14541464
if (tight or (len(self.images)>0 and
14551465
len(self.lines)==0 and
14561466
len(self.patches)==0)):
1457-
1458-
if scalex: self.set_xbound(self.dataLim.intervalx)
1459-
1460-
if scaley: self.set_ybound(self.dataLim.intervaly)
1467+
if scalex:
1468+
self.set_xbound(x0, x1)
1469+
if scaley:
1470+
self.set_ybound(y0, 11)
14611471
return
14621472

14631473
if scalex:
1464-
XL = self.xaxis.get_major_locator().autoscale()
1474+
XL = self.xaxis.get_major_locator().view_limits(x0, x1)
14651475
self.set_xbound(XL)
14661476
if scaley:
1467-
YL = self.yaxis.get_major_locator().autoscale()
1477+
YL = self.yaxis.get_major_locator().view_limits(y0, y1)
14681478
self.set_ybound(YL)
14691479

14701480
#### Drawing

lib/matplotlib/ticker.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,17 @@ def __call__(self):
641641
'Return the locations of the ticks'
642642
raise NotImplementedError('Derived must override')
643643

644+
def view_limits(self, vmin, vmax):
645+
"""
646+
select a scale for the range from vmin to vmax
647+
648+
Normally This will be overridden.
649+
"""
650+
return mtransforms.nonsingular(vmin, vmax)
651+
644652
def autoscale(self):
645653
'autoscale the view limits'
646-
return mtransforms.nonsingular(*self.axis.get_view_interval())
654+
return self.view_limits(*self.axis.get_view_interval())
647655

648656
def pan(self, numsteps):
649657
'Pan numticks (can be positive or negative)'
@@ -773,11 +781,9 @@ def __call__(self):
773781
def _set_numticks(self):
774782
self.numticks = 11 # todo; be smart here; this is just for dev
775783

776-
def autoscale(self):
784+
def view_limits(self, vmin, vmax):
777785
'Try to choose the view limits intelligently'
778786

779-
vmin, vmax = self.axis.get_data_interval()
780-
781787
if vmax<vmin:
782788
vmin, vmax = vmax, vmin
783789

@@ -859,13 +865,11 @@ def __call__(self):
859865
locs = vmin + np.arange(n+1) * base
860866
return locs
861867

862-
def autoscale(self):
868+
def view_limits(self, dmin, dmax):
863869
"""
864870
Set the view limits to the nearest multiples of base that
865871
contain the data
866872
"""
867-
dmin, dmax = self.axis.get_data_interval()
868-
869873
vmin = self._base.le(dmin)
870874
vmax = self._base.ge(dmax)
871875
if vmin==vmax:
@@ -946,8 +950,7 @@ def __call__(self):
946950
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
947951
return self.bin_boundaries(vmin, vmax)
948952

949-
def autoscale(self):
950-
dmin, dmax = self.axis.get_data_interval()
953+
def view_limits(self, dmin, dmax):
951954
if self._symmetric:
952955
maxabs = max(abs(dmin), abs(dmax))
953956
dmin = -maxabs
@@ -1043,9 +1046,9 @@ def __call__(self):
10431046

10441047
return np.array(ticklocs)
10451048

1046-
def autoscale(self):
1049+
def view_limits(self, vmin, vmax):
10471050
'Try to choose the view limits intelligently'
1048-
vmin, vmax = self.axis.get_data_interval()
1051+
10491052
if vmax<vmin:
10501053
vmin, vmax = vmax, vmin
10511054

@@ -1114,10 +1117,9 @@ def __call__(self):
11141117
ticklocs = np.sign(decades) * b ** np.abs(decades)
11151118
return np.array(ticklocs)
11161119

1117-
def autoscale(self):
1120+
def view_limits(self, vmin, vmax):
11181121
'Try to choose the view limits intelligently'
11191122
b = self._transform.base
1120-
vmin, vmax = self.axis.get_data_interval()
11211123
if vmax<vmin:
11221124
vmin, vmax = vmax, vmin
11231125

@@ -1167,13 +1169,12 @@ def refresh(self):
11671169
d = abs(vmax-vmin)
11681170
self._locator = self.get_locator(d)
11691171

1170-
def autoscale(self):
1172+
def view_limits(self, vmin, vmax):
11711173
'Try to choose the view limits intelligently'
11721174

1173-
vmin, vmax = self.axis.get_data_interval()
11741175
d = abs(vmax-vmin)
11751176
self._locator = self.get_locator(d)
1176-
return self._locator.autoscale()
1177+
return self._locator.view_limits(vmin, vmax)
11771178

11781179
def get_locator(self, d):
11791180
'pick the best locator based on a distance'

0 commit comments

Comments
 (0)