@@ -1314,7 +1314,9 @@ def __init__(self, offsetbox, xy,
1314
1314
*textcoords* in `.Annotation` for a detailed description.
1315
1315
1316
1316
frameon : bool, default: True
1317
- Whether to draw a frame around the box.
1317
+ By default, the text is surrounded by a white `.FancyBboxPatch`
1318
+ (accessible as the ``patch`` attribute of the `.AnnotationBbox`).
1319
+ If *frameon* is set to False, this patch is made invisible.
1318
1320
1319
1321
pad : float, default: 0.4
1320
1322
Padding around the offsetbox.
@@ -1329,10 +1331,9 @@ def __init__(self, offsetbox, xy,
1329
1331
"""
1330
1332
1331
1333
martist .Artist .__init__ (self )
1332
- mtext ._AnnotationBase .__init__ (self ,
1333
- xy ,
1334
- xycoords = xycoords ,
1335
- annotation_clip = annotation_clip )
1334
+ mtext ._AnnotationBase .__init__ (
1335
+ self , xy , xycoords = xycoords , annotation_clip = annotation_clip )
1336
+
1336
1337
self .offsetbox = offsetbox
1337
1338
self .arrowprops = arrowprops .copy () if arrowprops is not None else None
1338
1339
self .set_fontsize (fontsize )
@@ -1418,34 +1419,17 @@ def get_fontsize(self):
1418
1419
1419
1420
def get_window_extent (self , renderer ):
1420
1421
# docstring inherited
1421
- bboxes = [child .get_window_extent (renderer )
1422
- for child in self .get_children ()]
1423
-
1424
- return Bbox .union (bboxes )
1422
+ return Bbox .union ([child .get_window_extent (renderer )
1423
+ for child in self .get_children ()])
1425
1424
1426
1425
def get_tightbbox (self , renderer ):
1427
1426
# docstring inherited
1428
- bboxes = [child .get_tightbbox (renderer )
1429
- for child in self .get_children ()]
1430
-
1431
- return Bbox .union (bboxes )
1427
+ return Bbox .union ([child .get_tightbbox (renderer )
1428
+ for child in self .get_children ()])
1432
1429
1433
1430
def update_positions (self , renderer ):
1434
1431
"""
1435
- Update the pixel positions of the annotated point and the text.
1436
- """
1437
- xy_pixel = self ._get_position_xy (renderer )
1438
- self ._update_position_xybox (renderer , xy_pixel )
1439
-
1440
- mutation_scale = renderer .points_to_pixels (self .get_fontsize ())
1441
- self .patch .set_mutation_scale (mutation_scale )
1442
-
1443
- if self .arrow_patch :
1444
- self .arrow_patch .set_mutation_scale (mutation_scale )
1445
-
1446
- def _update_position_xybox (self , renderer , xy_pixel ):
1447
- """
1448
- Update the pixel positions of the annotation text and the arrow patch.
1432
+ Update pixel positions for the annotated point, the text and the arrow.
1449
1433
"""
1450
1434
1451
1435
x , y = self .xybox
@@ -1458,40 +1442,34 @@ def _update_position_xybox(self, renderer, xy_pixel):
1458
1442
ox0 , oy0 = self ._get_xy (renderer , x , y , self .boxcoords )
1459
1443
1460
1444
w , h , xd , yd = self .offsetbox .get_extent (renderer )
1445
+ fw , fh = self ._box_alignment
1446
+ self .offsetbox .set_offset ((ox0 - fw * w + xd , oy0 - fh * h + yd ))
1461
1447
1462
- _fw , _fh = self ._box_alignment
1463
- self .offsetbox .set_offset ((ox0 - _fw * w + xd , oy0 - _fh * h + yd ))
1464
-
1465
- # update patch position
1466
1448
bbox = self .offsetbox .get_window_extent (renderer )
1467
1449
self .patch .set_bounds (bbox .bounds )
1468
1450
1469
- ox1 , oy1 = xy_pixel
1451
+ mutation_scale = renderer .points_to_pixels (self .get_fontsize ())
1452
+ self .patch .set_mutation_scale (mutation_scale )
1470
1453
1471
1454
if self .arrowprops :
1472
- d = self .arrowprops .copy ()
1473
-
1474
1455
# Use FancyArrowPatch if self.arrowprops has "arrowstyle" key.
1475
1456
1476
1457
# Adjust the starting point of the arrow relative to the textbox.
1477
1458
# TODO: Rotation needs to be accounted.
1478
- relpos = self ._arrow_relpos
1479
-
1480
- ox0 = bbox .x0 + bbox .width * relpos [0 ]
1481
- oy0 = bbox .y0 + bbox .height * relpos [1 ]
1482
-
1483
- # The arrow will be drawn from (ox0, oy0) to (ox1, oy1).
1484
- # It will be first clipped by patchA and patchB.
1485
- # Then it will be shrunk by shrinkA and shrinkB (in points).
1486
- # If patch A is not set, self.bbox_patch is used.
1487
-
1488
- self .arrow_patch .set_positions ((ox0 , oy0 ), (ox1 , oy1 ))
1489
- fs = self .prop .get_size_in_points ()
1490
- mutation_scale = d .pop ("mutation_scale" , fs )
1491
- mutation_scale = renderer .points_to_pixels (mutation_scale )
1459
+ arrow_begin = bbox .p0 + bbox .size * self ._arrow_relpos
1460
+ arrow_end = self ._get_position_xy (renderer )
1461
+ # The arrow (from arrow_begin to arrow_end) will be first clipped
1462
+ # by patchA and patchB, then shrunk by shrinkA and shrinkB (in
1463
+ # points). If patch A is not set, self.bbox_patch is used.
1464
+ self .arrow_patch .set_positions (arrow_begin , arrow_end )
1465
+
1466
+ if "mutation_scale" in self .arrowprops :
1467
+ mutation_scale = renderer .points_to_pixels (
1468
+ self .arrowprops ["mutation_scale" ])
1469
+ # Else, use fontsize-based mutation_scale defined above.
1492
1470
self .arrow_patch .set_mutation_scale (mutation_scale )
1493
1471
1494
- patchA = d . pop ("patchA" , self .patch )
1472
+ patchA = self . arrowprops . get ("patchA" , self .patch )
1495
1473
self .arrow_patch .set_patchA (patchA )
1496
1474
1497
1475
def draw (self , renderer ):
0 commit comments