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):
14521452 self ._renderer = renderer
14531453 if not self .get_visible () or not self ._check_xy (renderer ):
14541454 return
1455+ renderer .open_group (self .__class__ .__name__ , gid = self .get_gid ())
14551456 self .update_positions (renderer )
14561457 if self .arrow_patch is not None :
14571458 if self .arrow_patch .figure is None and self .figure is not None :
14581459 self .arrow_patch .figure = self .figure
14591460 self .arrow_patch .draw (renderer )
14601461 self .patch .draw (renderer )
14611462 self .offsetbox .draw (renderer )
1463+ renderer .close_group (self .__class__ .__name__ )
14621464 self .stale = False
14631465
14641466
Original file line number Diff line number Diff line change 1515from matplotlib .testing .decorators import check_figures_equal , image_comparison
1616from matplotlib .testing ._markers import needs_usetex
1717from matplotlib import font_manager as fm
18+ from matplotlib .offsetbox import (OffsetImage , AnnotationBbox )
1819
1920
2021def test_visibility ():
@@ -609,3 +610,34 @@ def test_svg_font_string(font_str, include_generic):
609610
610611 assert font_info == f"{ size } px { font_str } "
611612 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