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