@@ -875,10 +875,7 @@ def set_position(self, pos, which='both'):
875
875
"""
876
876
if not isinstance (pos , mtransforms .BboxBase ):
877
877
pos = mtransforms .Bbox .from_bounds (* pos )
878
- twins = self ._twinned_axes .get_siblings (self )
879
- if not twins :
880
- twins = [self ]
881
- for ax in twins :
878
+ for ax in self ._twinned_axes .get_siblings (self ):
882
879
if which in ('both' , 'active' ):
883
880
ax ._position .set (pos )
884
881
if which in ('both' , 'original' ):
@@ -892,10 +889,7 @@ def reset_position(self):
892
889
This resets the a possible position change due to aspect constraints.
893
890
For an explanation of the positions see `.set_position`.
894
891
"""
895
- twins = self ._twinned_axes .get_siblings (self )
896
- if not twins :
897
- twins = [self ]
898
- for ax in twins :
892
+ for ax in self ._twinned_axes .get_siblings (self ):
899
893
pos = ax .get_position (original = True )
900
894
ax .set_position (pos , which = 'active' )
901
895
@@ -1302,6 +1296,10 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
1302
1296
1303
1297
See `.set_anchor` for further details.
1304
1298
1299
+ share : bool, optional
1300
+ If ``True``, apply the settings to all shared Axes.
1301
+ Default is ``False``.
1302
+
1305
1303
See Also
1306
1304
--------
1307
1305
matplotlib.axes.Axes.set_adjustable
@@ -1310,25 +1308,23 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
1310
1308
matplotlib.axes.Axes.set_anchor
1311
1309
defining the position in case of extra space.
1312
1310
"""
1313
- if (isinstance (aspect , six .string_types )
1311
+ if not (isinstance (aspect , six .string_types )
1314
1312
and aspect in ('equal' , 'auto' )):
1315
- self ._aspect = aspect
1313
+ aspect = float (aspect ) # raise ValueError if necessary
1314
+ if share :
1315
+ axes = set (self ._shared_x_axes .get_siblings (self )
1316
+ + self ._shared_y_axes .get_siblings (self ))
1316
1317
else :
1317
- self ._aspect = float (aspect ) # raise ValueError if necessary
1318
-
1319
- if share and self in self ._shared_x_axes :
1320
- for ax in self ._shared_x_axes .get_siblings (self ):
1321
- ax ._aspect = aspect
1322
- if share and self in self ._shared_y_axes :
1323
- for ax in self ._shared_y_axes .get_siblings (self ):
1324
- ax ._aspect = aspect
1318
+ axes = [self ]
1319
+ for ax in axes :
1320
+ ax ._aspect = aspect
1325
1321
1326
1322
if adjustable is None :
1327
1323
adjustable = self ._adjustable
1328
1324
self .set_adjustable (adjustable , share = share ) # Handle sharing.
1329
1325
1330
1326
if anchor is not None :
1331
- self .set_anchor (anchor )
1327
+ self .set_anchor (anchor ) # Also needs a "share" kwarg?
1332
1328
self .stale = True
1333
1329
1334
1330
def get_adjustable (self ):
@@ -1338,14 +1334,15 @@ def set_adjustable(self, adjustable, share=False):
1338
1334
"""
1339
1335
Define which parameter the Axes will change to achieve a given aspect.
1340
1336
1341
- Possible values are:
1337
+ Parameters
1338
+ ----------
1339
+ adjustable : ['box' | 'datalim']
1340
+ If 'box', change the physical dimensions of the Axes.
1341
+ If 'datalim', change the ``x`` or ``y`` data limits.
1342
1342
1343
- ============ =====================================
1344
- value description
1345
- ============ =====================================
1346
- 'box' change the physical size of the Axes
1347
- 'datalim' change xlim or ylim
1348
- ============ =====================================
1343
+ share : bool, optional
1344
+ If ``True``, apply the settings to all shared Axes.
1345
+ Default is ``False``.
1349
1346
1350
1347
..
1351
1348
ACCEPTS: [ 'box' | 'datalim']
@@ -1355,17 +1352,18 @@ def set_adjustable(self, adjustable, share=False):
1355
1352
matplotlib.axes.Axes.set_aspect
1356
1353
for a description of aspect handling.
1357
1354
"""
1358
- # FIXME: add box-forced deprecation
1359
- if adjustable in ('box' , 'datalim' , 'box-forced' ):
1360
- if share and self in self ._shared_x_axes :
1361
- for ax in self ._shared_x_axes .get_siblings (self ):
1362
- ax ._adjustable = adjustable
1363
- if share and self in self ._shared_y_axes :
1364
- for ax in self ._shared_y_axes .get_siblings (self ):
1365
- ax ._adjustable = adjustable
1366
- self ._adjustable = adjustable
1355
+ if adjustable == 'box-forced' :
1356
+ warnings .warn ("The 'box-forced' keyword argument is deprecated"
1357
+ " since 2.2." , mplDeprecation )
1358
+ if adjustable not in ('box' , 'datalim' , 'box-forced' ):
1359
+ raise ValueError ("argument must be 'box', or 'datalim'" )
1360
+ if share :
1361
+ axes = set (self ._shared_x_axes .get_siblings (self )
1362
+ + self ._shared_y_axes .get_siblings (self ))
1367
1363
else :
1368
- raise ValueError ('argument must be "box", or "datalim"' )
1364
+ axes = [self ]
1365
+ for ax in axes :
1366
+ ax ._adjustable = adjustable
1369
1367
self .stale = True
1370
1368
1371
1369
def get_anchor (self ):
@@ -1461,21 +1459,22 @@ def get_data_ratio_log(self):
1461
1459
1462
1460
def apply_aspect (self , position = None ):
1463
1461
"""
1464
- Adjust the Axes so that it fulfills its aspect setting .
1462
+ Adjust the Axes for a specified data aspect ratio .
1465
1463
1466
- Depending on `.get_adjustable` and `.get_anchor` this will either
1467
- modify the Axes box or the view limits.
1464
+ Depending on `.get_adjustable` this will modify either the Axes box
1465
+ (position) or the view limits. In the former case, `.get_anchor`
1466
+ will affect the position.
1468
1467
1469
1468
Notes
1470
1469
-----
1471
- This is automatically called on draw. So you won't need to call this
1472
- yourself in most cases. One exception may be if you need to update the
1473
- Axes before drawing .
1470
+ This is called automatically when each Axes is drawn. You may need
1471
+ to call it yourself if you need to update the Axes position and/or
1472
+ view limits before the Figure is drawn .
1474
1473
1475
1474
See Also
1476
1475
--------
1477
1476
matplotlib.axes.Axes.set_aspect
1478
- for a description of aspect handling.
1477
+ for a description of aspect ratio handling.
1479
1478
matplotlib.axes.Axes.set_adjustable
1480
1479
defining the parameter to adjust in order to meet the required
1481
1480
aspect.
@@ -4127,9 +4126,9 @@ def _make_twin_axes(self, *kl, **kwargs):
4127
4126
"""
4128
4127
# Typically, SubplotBase._make_twin_axes is called instead of this.
4129
4128
ax2 = self .figure .add_axes (self .get_position (True ), * kl , ** kwargs )
4130
- # do not touch every thing shared, just this and it's twin.
4131
- self .set_adjustable ('datalim' )
4132
- ax2 .set_adjustable ('datalim' )
4129
+ ## do not touch every thing shared, just this and it's twin.
4130
+ # self.set_adjustable('datalim')
4131
+ # ax2.set_adjustable('datalim')
4133
4132
self ._twinned_axes .join (self , ax2 )
4134
4133
return ax2
4135
4134
0 commit comments