@@ -1404,20 +1404,21 @@ def set_anchor(self, anchor, share=False):
1404
1404
1405
1405
def get_data_ratio (self ):
1406
1406
"""
1407
- Return the aspect ratio of the raw data.
1407
+ Return the aspect ratio of the scaled data.
1408
1408
1409
1409
Notes
1410
1410
-----
1411
1411
This method is intended to be overridden by new projection types.
1412
1412
"""
1413
- xmin , xmax = self . get_xbound ()
1414
- ymin , ymax = self .get_ybound ( )
1415
-
1416
- xsize = max ( abs ( xmax - xmin ), 1e-30 )
1417
- ysize = max (abs (ymax - ymin ), 1e-30 )
1418
-
1413
+ trf_xmin , trf_xmax = map (
1414
+ self .xaxis . get_transform (). transform , self . get_xbound () )
1415
+ trf_ymin , trf_ymax = map (
1416
+ self . yaxis . get_transform (). transform , self . get_ybound () )
1417
+ xsize = max (abs (trf_xmax - trf_xmin ), 1e-30 )
1418
+ ysize = max ( abs ( trf_ymax - trf_ymin ), 1e-30 )
1419
1419
return ysize / xsize
1420
1420
1421
+ @cbook .deprecated ("3.2" )
1421
1422
def get_data_ratio_log (self ):
1422
1423
"""
1423
1424
Return the aspect ratio of the raw data in log scale.
@@ -1463,99 +1464,70 @@ def apply_aspect(self, position=None):
1463
1464
1464
1465
aspect = self .get_aspect ()
1465
1466
1466
- if self .name != 'polar' :
1467
- xscale , yscale = self .get_xscale (), self .get_yscale ()
1468
- if xscale == "linear" and yscale == "linear" :
1469
- aspect_scale_mode = "linear"
1470
- elif xscale == "log" and yscale == "log" :
1471
- aspect_scale_mode = "log"
1472
- elif ((xscale == "linear" and yscale == "log" ) or
1473
- (xscale == "log" and yscale == "linear" )):
1474
- if aspect != "auto" :
1475
- cbook ._warn_external (
1476
- 'aspect is not supported for Axes with xscale=%s, '
1477
- 'yscale=%s' % (xscale , yscale ))
1478
- aspect = "auto"
1479
- else : # some custom projections have their own scales.
1480
- pass
1481
- else :
1482
- aspect_scale_mode = "linear"
1483
-
1484
1467
if aspect == 'auto' :
1485
1468
self ._set_position (position , which = 'active' )
1486
1469
return
1487
1470
1488
1471
if aspect == 'equal' :
1489
- A = 1
1490
- else :
1491
- A = aspect
1472
+ aspect = 1
1473
+
1474
+ fig_width , fig_height = self .get_figure ().get_size_inches ()
1475
+ fig_aspect = fig_height / fig_width
1492
1476
1493
- figW , figH = self .get_figure ().get_size_inches ()
1494
- fig_aspect = figH / figW
1495
1477
if self ._adjustable == 'box' :
1496
1478
if self in self ._twinned_axes :
1497
- raise RuntimeError ("Adjustable 'box' is not allowed in a"
1498
- " twinned Axes. Use 'datalim' instead." )
1499
- if aspect_scale_mode == "log" :
1500
- box_aspect = A * self .get_data_ratio_log ()
1501
- else :
1502
- box_aspect = A * self .get_data_ratio ()
1479
+ raise RuntimeError ("Adjustable 'box' is not allowed in a "
1480
+ "twinned Axes; use 'datalim' instead" )
1481
+ box_aspect = aspect * self .get_data_ratio ()
1503
1482
pb = position .frozen ()
1504
1483
pb1 = pb .shrunk_to_aspect (box_aspect , pb , fig_aspect )
1505
1484
self ._set_position (pb1 .anchored (self .get_anchor (), pb ), 'active' )
1506
1485
return
1507
1486
1508
- # reset active to original in case it had been changed
1509
- # by prior use of 'box'
1510
- self ._set_position (position , which = 'active' )
1511
-
1512
- xmin , xmax = self .get_xbound ()
1513
- ymin , ymax = self .get_ybound ()
1487
+ # self._adjustable == 'datalim'
1514
1488
1515
- if aspect_scale_mode == "log" :
1516
- xmin , xmax = math . log10 ( xmin ), math . log10 ( xmax )
1517
- ymin , ymax = math . log10 ( ymin ), math . log10 ( ymax )
1489
+ # reset active to original in case it had been changed by prior use
1490
+ # of 'box'
1491
+ self . _set_position ( position , which = 'active' )
1518
1492
1493
+ x_trf = self .xaxis .get_transform ()
1494
+ y_trf = self .yaxis .get_transform ()
1495
+ xmin , xmax = map (x_trf .transform , self .get_xbound ())
1496
+ ymin , ymax = map (y_trf .transform , self .get_ybound ())
1519
1497
xsize = max (abs (xmax - xmin ), 1e-30 )
1520
1498
ysize = max (abs (ymax - ymin ), 1e-30 )
1521
1499
1522
1500
l , b , w , h = position .bounds
1523
1501
box_aspect = fig_aspect * (h / w )
1524
- data_ratio = box_aspect / A
1502
+ data_ratio = box_aspect / aspect
1525
1503
1526
- y_expander = ( data_ratio * xsize / ysize - 1.0 )
1504
+ y_expander = data_ratio * xsize / ysize - 1
1527
1505
# If y_expander > 0, the dy/dx viewLim ratio needs to increase
1528
1506
if abs (y_expander ) < 0.005 :
1529
1507
return
1530
1508
1531
- if aspect_scale_mode == "log" :
1532
- dL = self .dataLim
1533
- dL_width = math .log10 (dL .x1 ) - math .log10 (dL .x0 )
1534
- dL_height = math .log10 (dL .y1 ) - math .log10 (dL .y0 )
1535
- xr = 1.05 * dL_width
1536
- yr = 1.05 * dL_height
1537
- else :
1538
- dL = self .dataLim
1539
- xr = 1.05 * dL .width
1540
- yr = 1.05 * dL .height
1509
+ dL = self .dataLim
1510
+ x0 , x1 = map (x_trf .inverted ().transform , dL .intervalx )
1511
+ y0 , y1 = map (y_trf .inverted ().transform , dL .intervaly )
1512
+ xr = 1.05 * (x1 - x0 )
1513
+ yr = 1.05 * (y1 - y0 )
1541
1514
1542
1515
xmarg = xsize - xr
1543
1516
ymarg = ysize - yr
1544
1517
Ysize = data_ratio * xsize
1545
1518
Xsize = ysize / data_ratio
1546
1519
Xmarg = Xsize - xr
1547
1520
Ymarg = Ysize - yr
1548
- # Setting these targets to, e.g., 0.05*xr does not seem to
1549
- # help.
1521
+ # Setting these targets to, e.g., 0.05*xr does not seem to help.
1550
1522
xm = 0
1551
1523
ym = 0
1552
1524
1553
1525
shared_x = self in self ._shared_x_axes
1554
1526
shared_y = self in self ._shared_y_axes
1555
1527
# Not sure whether we need this check:
1556
1528
if shared_x and shared_y :
1557
- raise RuntimeError ("adjustable='datalim' is not allowed when both"
1558
- " axes are shared. " )
1529
+ raise RuntimeError ("adjustable='datalim' is not allowed when both "
1530
+ "axes are shared" )
1559
1531
1560
1532
# If y is shared, then we are only allowed to change x, etc.
1561
1533
if shared_y :
@@ -1572,18 +1544,12 @@ def apply_aspect(self, position=None):
1572
1544
yc = 0.5 * (ymin + ymax )
1573
1545
y0 = yc - Ysize / 2.0
1574
1546
y1 = yc + Ysize / 2.0
1575
- if aspect_scale_mode == "log" :
1576
- self .set_ybound ((10. ** y0 , 10. ** y1 ))
1577
- else :
1578
- self .set_ybound ((y0 , y1 ))
1547
+ self .set_ybound (* map (y_trf .inverted ().transform , (y0 , y1 )))
1579
1548
else :
1580
1549
xc = 0.5 * (xmin + xmax )
1581
1550
x0 = xc - Xsize / 2.0
1582
1551
x1 = xc + Xsize / 2.0
1583
- if aspect_scale_mode == "log" :
1584
- self .set_xbound ((10. ** x0 , 10. ** x1 ))
1585
- else :
1586
- self .set_xbound ((x0 , x1 ))
1552
+ self .set_xbound (* map (x_trf .inverted ().transform , (x0 , x1 )))
1587
1553
1588
1554
def axis (self , * args , emit = True , ** kwargs ):
1589
1555
"""
0 commit comments