@@ -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,127 +1456,92 @@ 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 ()
1506
-
1507
- if aspect_scale_mode == "log" :
1508
- xmin , xmax = math .log10 (xmin ), math .log10 (xmax )
1509
- ymin , ymax = math .log10 (ymin ), math .log10 (ymax )
1479
+ elif self ._adjustable == 'datalim' :
1480
+ # reset active to original in case it had been changed by prior use
1481
+ # of 'box'
1482
+ self ._set_position (position , which = 'active' )
1510
1483
1511
- xsize = max (abs (xmax - xmin ), 1e-30 )
1512
- ysize = max (abs (ymax - ymin ), 1e-30 )
1484
+ x_trf = self .xaxis .get_transform ()
1485
+ y_trf = self .yaxis .get_transform ()
1486
+ xmin , xmax = map (x_trf .transform , self .get_xbound ())
1487
+ ymin , ymax = map (y_trf .transform , self .get_ybound ())
1488
+ xsize = max (abs (xmax - xmin ), 1e-30 )
1489
+ ysize = max (abs (ymax - ymin ), 1e-30 )
1513
1490
1514
- l , b , w , h = position .bounds
1515
- box_aspect = fig_aspect * (h / w )
1516
- data_ratio = box_aspect / A
1491
+ l , b , w , h = position .bounds
1492
+ box_aspect = fig_aspect * (h / w )
1493
+ data_ratio = box_aspect / aspect
1517
1494
1518
- y_expander = ( data_ratio * xsize / ysize - 1.0 )
1519
- # If y_expander > 0, the dy/dx viewLim ratio needs to increase
1520
- if abs (y_expander ) < 0.005 :
1521
- return
1495
+ y_expander = data_ratio * xsize / ysize - 1
1496
+ # If y_expander > 0, the dy/dx viewLim ratio needs to increase
1497
+ if abs (y_expander ) < 0.005 :
1498
+ return
1522
1499
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
1500
dL = self .dataLim
1531
- xr = 1.05 * dL .width
1532
- yr = 1.05 * dL .height
1533
-
1534
- xmarg = xsize - xr
1535
- ymarg = ysize - yr
1536
- Ysize = data_ratio * xsize
1537
- Xsize = ysize / data_ratio
1538
- Xmarg = Xsize - xr
1539
- Ymarg = Ysize - yr
1540
- # Setting these targets to, e.g., 0.05*xr does not seem to
1541
- # help.
1542
- xm = 0
1543
- ym = 0
1544
-
1545
- shared_x = self in self ._shared_x_axes
1546
- shared_y = self in self ._shared_y_axes
1547
- # Not sure whether we need this check:
1548
- if shared_x and shared_y :
1549
- raise RuntimeError ("adjustable='datalim' is not allowed when both"
1550
- " axes are shared." )
1551
-
1552
- # If y is shared, then we are only allowed to change x, etc.
1553
- if shared_y :
1554
- adjust_y = False
1555
- else :
1556
- if xmarg > xm and ymarg > ym :
1557
- adjy = ((Ymarg > 0 and y_expander < 0 ) or
1558
- (Xmarg < 0 and y_expander > 0 ))
1559
- else :
1560
- adjy = y_expander > 0
1561
- adjust_y = shared_x or adjy # (Ymarg > xmarg)
1562
-
1563
- if adjust_y :
1564
- yc = 0.5 * (ymin + ymax )
1565
- y0 = yc - Ysize / 2.0
1566
- y1 = yc + Ysize / 2.0
1567
- if aspect_scale_mode == "log" :
1568
- self .set_ybound ((10. ** y0 , 10. ** y1 ))
1501
+ x0 , x1 = map (x_trf .inverted ().transform , dL .intervalx )
1502
+ y0 , y1 = map (y_trf .inverted ().transform , dL .intervaly )
1503
+ xr = 1.05 * (x1 - x0 )
1504
+ yr = 1.05 * (y1 - y0 )
1505
+
1506
+ xmarg = xsize - xr
1507
+ ymarg = ysize - yr
1508
+ Ysize = data_ratio * xsize
1509
+ Xsize = ysize / data_ratio
1510
+ Xmarg = Xsize - xr
1511
+ Ymarg = Ysize - yr
1512
+ # Setting these targets to, e.g., 0.05*xr does not seem to help.
1513
+ xm = 0
1514
+ ym = 0
1515
+
1516
+ shared_x = self in self ._shared_x_axes
1517
+ shared_y = self in self ._shared_y_axes
1518
+ # Not sure whether we need this check:
1519
+ if shared_x and shared_y :
1520
+ raise RuntimeError ("adjustable='datalim' is not allowed when "
1521
+ "both axes are shared" )
1522
+
1523
+ # If y is shared, then we are only allowed to change x, etc.
1524
+ if shared_y :
1525
+ adjust_y = False
1569
1526
else :
1570
- self .set_ybound ((y0 , y1 ))
1571
- else :
1572
- xc = 0.5 * (xmin + xmax )
1573
- x0 = xc - Xsize / 2.0
1574
- x1 = xc + Xsize / 2.0
1575
- if aspect_scale_mode == "log" :
1576
- self .set_xbound ((10. ** x0 , 10. ** x1 ))
1527
+ if xmarg > xm and ymarg > ym :
1528
+ adjy = ((Ymarg > 0 and y_expander < 0 ) or
1529
+ (Xmarg < 0 and y_expander > 0 ))
1530
+ else :
1531
+ adjy = y_expander > 0
1532
+ adjust_y = shared_x or adjy # (Ymarg > xmarg)
1533
+
1534
+ if adjust_y :
1535
+ yc = 0.5 * (ymin + ymax )
1536
+ y0 = yc - Ysize / 2.0
1537
+ y1 = yc + Ysize / 2.0
1538
+ self .set_ybound (* map (y_trf .inverted ().transform , (y0 , y1 )))
1577
1539
else :
1578
- self .set_xbound ((x0 , x1 ))
1540
+ xc = 0.5 * (xmin + xmax )
1541
+ x0 = xc - Xsize / 2.0
1542
+ x1 = xc + Xsize / 2.0
1543
+ self .set_xbound (* map (x_trf .inverted ().transform , (x0 , x1 )))
1544
+ return
1579
1545
1580
1546
def axis (self , * args , emit = True , ** kwargs ):
1581
1547
"""
0 commit comments