@@ -414,6 +414,7 @@ class _AxesBase(martist.Artist):
414
414
415
415
_shared_x_axes = cbook .Grouper ()
416
416
_shared_y_axes = cbook .Grouper ()
417
+ _twinned_axes = cbook .Grouper ()
417
418
418
419
def __str__ (self ):
419
420
return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})" .format (
@@ -874,10 +875,14 @@ def set_position(self, pos, which='both'):
874
875
"""
875
876
if not isinstance (pos , mtransforms .BboxBase ):
876
877
pos = mtransforms .Bbox .from_bounds (* pos )
877
- if which in ('both' , 'active' ):
878
- self ._position .set (pos )
879
- if which in ('both' , 'original' ):
880
- self ._originalPosition .set (pos )
878
+ twins = self ._twinned_axes .get_siblings (self )
879
+ if not twins :
880
+ twins = [self ]
881
+ for ax in twins :
882
+ if which in ('both' , 'active' ):
883
+ ax ._position .set (pos )
884
+ if which in ('both' , 'original' ):
885
+ ax ._originalPosition .set (pos )
881
886
self .stale = True
882
887
883
888
def reset_position (self ):
@@ -887,8 +892,12 @@ def reset_position(self):
887
892
This resets the a possible position change due to aspect constraints.
888
893
For an explanation of the positions see `.set_position`.
889
894
"""
890
- pos = self .get_position (original = True )
891
- self .set_position (pos , which = 'active' )
895
+ twins = self ._twinned_axes .get_siblings (self )
896
+ if not twins :
897
+ twins = [self ]
898
+ for ax in twins :
899
+ pos = ax .get_position (original = True )
900
+ ax .set_position (pos , which = 'active' )
892
901
893
902
def set_axes_locator (self , locator ):
894
903
"""
@@ -4116,10 +4125,12 @@ def _make_twin_axes(self, *kl, **kwargs):
4116
4125
"""
4117
4126
make a twinx axes of self. This is used for twinx and twiny.
4118
4127
"""
4128
+ # Typically, SubplotBase._make_twin_axes is called instead of this.
4119
4129
ax2 = self .figure .add_axes (self .get_position (True ), * kl , ** kwargs )
4120
4130
# do not touch every thing shared, just this and it's twin.
4121
4131
self .set_adjustable ('datalim' )
4122
4132
ax2 .set_adjustable ('datalim' )
4133
+ self ._twinned_axes .join (self , ax2 )
4123
4134
return ax2
4124
4135
4125
4136
def twinx (self ):
0 commit comments