Skip to content

Commit be652cd

Browse files
itziakostacaswell
authored andcommitted
add test for annotation with text and arrow
1 parent e124465 commit be652cd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/matplotlib/tests/test_text.py

+31
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,37 @@ def test_text_annotation_get_window_extent():
298298
eq_(points[0, 1], -below_line)
299299
eq_(points[1, 1], text_bbox.height - below_line)
300300

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+
301332
def test_arrow_annotation_get_window_extent():
302333
from matplotlib.figure import Figure
303334
from matplotlib.text import Annotation

0 commit comments

Comments
 (0)