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

Skip to content

Commit 5c2382e

Browse files
committed
Make shared axes work better with constrained aspect ratio.
This is restricted to the case of adjustable=datalim, and is experimental. svn path=/trunk/matplotlib/; revision=6316
1 parent 5964da2 commit 5c2382e

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,24 @@ def __init__(self, fig, rect,
499499
self._originalPosition = self._position.frozen()
500500
self.set_axes(self)
501501
self.set_aspect('auto')
502-
self.set_adjustable('box')
502+
self._adjustable = 'box'
503503
self.set_anchor('C')
504504
self._sharex = sharex
505505
self._sharey = sharey
506506
if sharex is not None:
507507
self._shared_x_axes.join(self, sharex)
508+
if sharex._adjustable == 'box':
509+
sharex._adjustable = 'datalim'
510+
#warnings.warn(
511+
# 'shared axes: "adjustable" is being changed to "datalim"')
512+
self._adjustable = 'datalim'
508513
if sharey is not None:
509514
self._shared_y_axes.join(self, sharey)
510-
515+
if sharex._adjustable == 'box':
516+
sharex._adjustable = 'datalim'
517+
#warnings.warn(
518+
# 'shared axes: "adjustable" is being changed to "datalim"')
519+
self._adjustable = 'datalim'
511520
self.set_label(label)
512521
self.set_figure(fig)
513522

@@ -772,6 +781,11 @@ def set_position(self, pos, which='both'):
772781
if which in ('both', 'original'):
773782
self._originalPosition.set(pos)
774783

784+
def reset_position(self):
785+
'Make the original position the active position'
786+
pos = self.get_position(original=True)
787+
self.set_position(pos, which='active')
788+
775789
def _set_artist_props(self, a):
776790
'set the boilerplate props for artists added to axes'
777791
a.set_figure(self.figure)
@@ -992,6 +1006,10 @@ def set_adjustable(self, adjustable):
9921006
ACCEPTS: [ 'box' | 'datalim' ]
9931007
"""
9941008
if adjustable in ('box', 'datalim'):
1009+
if self in self._shared_x_axes or self in self._shared_y_axes:
1010+
if adjustable == 'box':
1011+
raise ValueError(
1012+
'adjustable must be "datalim" for shared axes')
9951013
self._adjustable = adjustable
9961014
else:
9971015
raise ValueError('argument must be "box", or "datalim"')
@@ -1043,11 +1061,11 @@ def apply_aspect(self, position=None):
10431061
axes box or the view limits.
10441062
'''
10451063
if position is None:
1046-
position = self.get_position(True)
1064+
position = self.get_position(original=True)
10471065

10481066
aspect = self.get_aspect()
10491067
if aspect == 'auto':
1050-
self.set_position( position , 'active')
1068+
self.set_position( position , which='active')
10511069
return
10521070

10531071
if aspect == 'equal':
@@ -1058,7 +1076,10 @@ def apply_aspect(self, position=None):
10581076
#Ensure at drawing time that any Axes involved in axis-sharing
10591077
# does not have its position changed.
10601078
if self in self._shared_x_axes or self in self._shared_y_axes:
1061-
self._adjustable = 'datalim'
1079+
if self._adjustable == 'box':
1080+
self._adjustable = 'datalim'
1081+
warnings.warn(
1082+
'shared axes: "adjustable" is being changed to "datalim"')
10621083

10631084
figW,figH = self.get_figure().get_size_inches()
10641085
fig_aspect = figH/figW
@@ -1069,6 +1090,10 @@ def apply_aspect(self, position=None):
10691090
self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
10701091
return
10711092

1093+
# reset active to original in case it had been changed
1094+
# by prior use of 'box'
1095+
self.set_position(position, which='active')
1096+
10721097
xmin,xmax = self.get_xbound()
10731098
xsize = max(math.fabs(xmax-xmin), 1e-30)
10741099
ymin,ymax = self.get_ybound()
@@ -1489,7 +1514,7 @@ def draw(self, renderer=None, inframe=False):
14891514
if not self.get_visible(): return
14901515
renderer.open_group('axes')
14911516

1492-
self.apply_aspect(self.get_position(True))
1517+
self.apply_aspect()
14931518

14941519
# the patch draws the background rectangle -- the frame below
14951520
# will draw the edges

0 commit comments

Comments
 (0)