@@ -1478,13 +1478,13 @@ def _get_xy_transform(self, renderer, coords):
1478
1478
trans = tr + self .axes .transData
1479
1479
return trans
1480
1480
1481
- s_ = coords .split ()
1482
- if len (s_ ) != 2 :
1483
- raise ValueError (f"{ coords !r} is not a valid coordinate" )
1481
+ try :
1482
+ bbox_name , unit = coords .split ()
1483
+ except ValueError : # i.e. len(coords.split()) != 2.
1484
+ raise ValueError (f"{ coords !r} is not a valid coordinate" ) from None
1484
1485
1485
1486
bbox0 , xy0 = None , None
1486
1487
1487
- bbox_name , unit = s_
1488
1488
# if unit is offset-like
1489
1489
if bbox_name == "figure" :
1490
1490
bbox0 = self .figure .figbbox
@@ -1493,35 +1493,27 @@ def _get_xy_transform(self, renderer, coords):
1493
1493
elif bbox_name == "axes" :
1494
1494
bbox0 = self .axes .bbox
1495
1495
1496
+ # reference x, y in display coordinate
1496
1497
if bbox0 is not None :
1497
1498
xy0 = bbox0 .p0
1498
1499
elif bbox_name == "offset" :
1499
1500
xy0 = self ._get_position_xy (renderer )
1500
-
1501
- if xy0 is not None :
1502
- # reference x, y in display coordinate
1503
- ref_x , ref_y = xy0
1504
- if unit == "points" :
1505
- # dots per points
1506
- dpp = self .figure .dpi / 72
1507
- tr = Affine2D ().scale (dpp )
1508
- elif unit == "pixels" :
1509
- tr = Affine2D ()
1510
- elif unit == "fontsize" :
1511
- fontsize = self .get_size ()
1512
- dpp = fontsize * self .figure .dpi / 72
1513
- tr = Affine2D ().scale (dpp )
1514
- elif unit == "fraction" :
1515
- w , h = bbox0 .size
1516
- tr = Affine2D ().scale (w , h )
1517
- else :
1518
- raise ValueError (f"{ unit !r} is not a recognized unit" )
1519
-
1520
- return tr .translate (ref_x , ref_y )
1521
-
1522
1501
else :
1523
1502
raise ValueError (f"{ coords !r} is not a valid coordinate" )
1524
1503
1504
+ if unit == "points" :
1505
+ tr = Affine2D ().scale (self .figure .dpi / 72 ) # dpi/72 dots per point
1506
+ elif unit == "pixels" :
1507
+ tr = Affine2D ()
1508
+ elif unit == "fontsize" :
1509
+ tr = Affine2D ().scale (self .get_size () * self .figure .dpi / 72 )
1510
+ elif unit == "fraction" :
1511
+ tr = Affine2D ().scale (* bbox0 .size )
1512
+ else :
1513
+ raise ValueError (f"{ unit !r} is not a recognized unit" )
1514
+
1515
+ return tr .translate (* xy0 )
1516
+
1525
1517
def set_annotation_clip (self , b ):
1526
1518
"""
1527
1519
Set the annotation's clipping behavior.
@@ -1701,15 +1693,15 @@ def transform(renderer) -> Transform
1701
1693
or callable, default: value of *xycoords*
1702
1694
The coordinate system that *xytext* is given in.
1703
1695
1704
- All *xycoords* values are valid as well as the following
1705
- strings:
1696
+ All *xycoords* values are valid as well as the following strings:
1706
1697
1707
- ================= =========================================
1698
+ ================= =================================================
1708
1699
Value Description
1709
- ================= =========================================
1710
- 'offset points' Offset (in points) from the *xy* value
1711
- 'offset pixels' Offset (in pixels) from the *xy* value
1712
- ================= =========================================
1700
+ ================= =================================================
1701
+ 'offset points' Offset, in points, from the *xy* value
1702
+ 'offset pixels' Offset, in pixels, from the *xy* value
1703
+ 'offset fontsize' Offset, relative to fontsize, from the *xy* value
1704
+ ================= =================================================
1713
1705
1714
1706
arrowprops : dict, optional
1715
1707
The properties used to draw a `.FancyArrowPatch` arrow between the
0 commit comments