@@ -426,6 +426,7 @@ def __init__(self, fig, rect,
426
426
self .axes = self
427
427
self ._aspect = 'auto'
428
428
self ._adjustable = 'box'
429
+ self ._box_aspect = None
429
430
self ._anchor = 'C'
430
431
self ._stale_viewlim_x = False
431
432
self ._stale_viewlim_y = False
@@ -1282,6 +1283,18 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
1282
1283
self .stale = True
1283
1284
1284
1285
def get_adjustable (self ):
1286
+ """
1287
+ Returns the adjustable parameter, *{'box', 'datalim'}* that defines
1288
+ which parameter the Axes will change to achieve a given aspect.
1289
+
1290
+ See Also
1291
+ --------
1292
+ matplotlib.axes.Axes.set_adjustable
1293
+ defining the parameter to adjust in order to meet the required
1294
+ aspect.
1295
+ matplotlib.axes.Axes.set_aspect
1296
+ for a description of aspect handling.
1297
+ """
1285
1298
return self ._adjustable
1286
1299
1287
1300
def set_adjustable (self , adjustable , share = False ):
@@ -1333,6 +1346,29 @@ def set_adjustable(self, adjustable, share=False):
1333
1346
ax ._adjustable = adjustable
1334
1347
self .stale = True
1335
1348
1349
+ def get_box_aspect (self ):
1350
+ """
1351
+ Get the axes box aspect.
1352
+ Will be ``None`` if not explicitely specified.
1353
+ """
1354
+ return self ._box_aspect
1355
+
1356
+ def set_box_aspect (self , aspect = None ):
1357
+ """ Set the axes box aspect. May be ``None`` or a number."""
1358
+ axs = {* self ._twinned_axes .get_siblings (self ),
1359
+ * self ._twinned_axes .get_siblings (self )}
1360
+
1361
+ if aspect is not None :
1362
+ aspect = float (aspect )
1363
+ # when box_aspect is set to other than ´None`,
1364
+ # adjustable must be "datalim"
1365
+ for ax in axs :
1366
+ ax .set_adjustable ("datalim" )
1367
+
1368
+ for ax in axs :
1369
+ ax ._box_aspect = aspect
1370
+ ax .stale = True
1371
+
1336
1372
def get_anchor (self ):
1337
1373
"""
1338
1374
Get the anchor location.
@@ -1464,7 +1500,7 @@ def apply_aspect(self, position=None):
1464
1500
1465
1501
aspect = self .get_aspect ()
1466
1502
1467
- if aspect == 'auto' :
1503
+ if aspect == 'auto' and self . _box_aspect is None :
1468
1504
self ._set_position (position , which = 'active' )
1469
1505
return
1470
1506
@@ -1484,11 +1520,20 @@ def apply_aspect(self, position=None):
1484
1520
self ._set_position (pb1 .anchored (self .get_anchor (), pb ), 'active' )
1485
1521
return
1486
1522
1487
- # self._adjustable == 'datalim'
1523
+ # The following is only seen if self._adjustable == 'datalim'
1524
+ if self ._box_aspect is not None :
1525
+ pb = position .frozen ()
1526
+ pb1 = pb .shrunk_to_aspect (self ._box_aspect , pb , fig_aspect )
1527
+ self ._set_position (pb1 .anchored (self .get_anchor (), pb ), 'active' )
1528
+ if aspect == "auto" :
1529
+ return
1488
1530
1489
1531
# reset active to original in case it had been changed by prior use
1490
1532
# of 'box'
1491
- self ._set_position (position , which = 'active' )
1533
+ if self ._box_aspect is None :
1534
+ self ._set_position (position , which = 'active' )
1535
+ else :
1536
+ position = pb1 .anchored (self .get_anchor (), pb )
1492
1537
1493
1538
x_trf = self .xaxis .get_transform ()
1494
1539
y_trf = self .yaxis .get_transform ()
0 commit comments