File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1452,13 +1452,15 @@ def draw(self, renderer):
1452
1452
self ._renderer = renderer
1453
1453
if not self .get_visible () or not self ._check_xy (renderer ):
1454
1454
return
1455
+ renderer .open_group (self .__class__ .__name__ , gid = self .get_gid ())
1455
1456
self .update_positions (renderer )
1456
1457
if self .arrow_patch is not None :
1457
1458
if self .arrow_patch .figure is None and self .figure is not None :
1458
1459
self .arrow_patch .figure = self .figure
1459
1460
self .arrow_patch .draw (renderer )
1460
1461
self .patch .draw (renderer )
1461
1462
self .offsetbox .draw (renderer )
1463
+ renderer .close_group (self .__class__ .__name__ )
1462
1464
self .stale = False
1463
1465
1464
1466
Original file line number Diff line number Diff line change 15
15
from matplotlib .testing .decorators import check_figures_equal , image_comparison
16
16
from matplotlib .testing ._markers import needs_usetex
17
17
from matplotlib import font_manager as fm
18
+ from matplotlib .offsetbox import (OffsetImage , AnnotationBbox )
18
19
19
20
20
21
def test_visibility ():
@@ -609,3 +610,34 @@ def test_svg_font_string(font_str, include_generic):
609
610
610
611
assert font_info == f"{ size } px { font_str } "
611
612
assert text_count == len (ax .texts )
613
+
614
+
615
+ def test_annotationbbox_gid ():
616
+ # Test that object gid appears in the AnnotationBbox
617
+ # in output svg.
618
+ fig = plt .figure ()
619
+ ax = fig .add_subplot ()
620
+ arr_img = np .ones ((32 , 32 ))
621
+ xy = (0.3 , 0.55 )
622
+
623
+ imagebox = OffsetImage (arr_img , zoom = 0.1 )
624
+ imagebox .image .axes = ax
625
+
626
+ ab = AnnotationBbox (imagebox , xy ,
627
+ xybox = (120. , - 80. ),
628
+ xycoords = 'data' ,
629
+ boxcoords = "offset points" ,
630
+ pad = 0.5 ,
631
+ arrowprops = dict (
632
+ arrowstyle = "->" ,
633
+ connectionstyle = "angle,angleA=0,angleB=90,rad=3" )
634
+ )
635
+ ab .set_gid ("a test for issue 20044" )
636
+ ax .add_artist (ab )
637
+
638
+ with BytesIO () as fd :
639
+ fig .savefig (fd , format = 'svg' )
640
+ buf = fd .getvalue ().decode ('utf-8' )
641
+
642
+ expected = '<g id="a test for issue 20044">'
643
+ assert expected in buf
You can’t perform that action at this time.
0 commit comments