@@ -298,6 +298,37 @@ def test_text_annotation_get_window_extent():
298
298
eq_ (points [0 , 1 ], - below_line )
299
299
eq_ (points [1 , 1 ], text_bbox .height - below_line )
300
300
301
+
302
+ def test_text_with_arrow_annotation_get_window_extent ():
303
+ from matplotlib .figure import Figure
304
+ from matplotlib .text import Annotation , Text
305
+ from matplotlib .backends .backend_agg import RendererAgg
306
+
307
+ figure = Figure (dpi = 100 )
308
+ renderer = RendererAgg (600 , 600 , 100 )
309
+ headwidth = 21
310
+
311
+ text = Text (text = 'test' , x = 0 , y = 0 )
312
+ text .set_figure (figure )
313
+ text_bbox = text .get_window_extent (renderer = renderer )
314
+
315
+ # Text annotation with arrow
316
+ annotation = Annotation (
317
+ 'test' ,
318
+ xy = (0.0 , 50.0 + (headwidth / 0.72 ) * 0.5 ),
319
+ xytext = (50.0 , 50.0 ), xycoords = 'figure pixels' ,
320
+ arrowprops = {
321
+ 'facecolor' : 'black' , 'width' : 2 ,
322
+ 'headwidth' : headwidth , 'shrink' : 0.0 })
323
+ annotation .set_figure (figure )
324
+ annotation .draw (renderer )
325
+
326
+ bbox = annotation .get_window_extent (renderer = renderer )
327
+ eq_ (bbox .width , text_bbox .width + 50.0 )
328
+ expected_height = max (text_bbox .height , headwidth / 0.72 )
329
+ assert_almost_equal (bbox .height , expected_height )
330
+
331
+
301
332
def test_arrow_annotation_get_window_extent ():
302
333
from matplotlib .figure import Figure
303
334
from matplotlib .text import Annotation
0 commit comments