Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cabefcc

Browse files
itziakostacaswell
authored andcommitted
add tests for empty and arrow only annotation
Conflicts: lib/matplotlib/tests/test_text.py
1 parent 9d1c876 commit cabefcc

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
99
import matplotlib.pyplot as plt
1010
import warnings
11-
from nose.tools import with_setup
11+
from nose import SkipTest
12+
from nose.tools import with_setup, assert_raises, eq_, ok_
1213

1314

1415
@image_comparison(baseline_images=['font_styles'])
@@ -260,3 +261,55 @@ def test_annotation_negative_coords():
260261
ax.annotate("-fpx", (-45, -30), xycoords="figure pixels")
261262
ax.annotate("-apt", (-35, -20), xycoords="axes points")
262263
ax.annotate("-apx", (-25, -10), xycoords="axes pixels")
264+
265+
266+
def test_arrow_annotation_get_window_extent():
267+
from matplotlib.figure import Figure
268+
from matplotlib.text import Annotation
269+
from matplotlib.backends.backend_agg import RendererAgg
270+
271+
figure = Figure(dpi=100)
272+
figure.set_figwidth(2.0)
273+
figure.set_figheight(2.0)
274+
renderer = RendererAgg(200, 200, 100)
275+
276+
# Text annotation with arrow
277+
annotation = Annotation(
278+
'', xy=(0.0, 50.0), xytext=(50.0, 50.0), xycoords='figure pixels',
279+
arrowprops={
280+
'facecolor': 'black', 'width': 8, 'headwidth': 10, 'shrink': 0.0})
281+
annotation.set_figure(figure)
282+
annotation.draw(renderer)
283+
284+
bbox = annotation.get_window_extent()
285+
points = bbox.get_points()
286+
287+
eq_(bbox.width, 50.0)
288+
assert_almost_equal(bbox.height, 10.0 / 0.72)
289+
eq_(points[0, 0], 0.0)
290+
eq_(points[0, 1], 50.0 - 5 / 0.72)
291+
292+
293+
def test_empty_annotation_get_window_extent():
294+
from matplotlib.figure import Figure
295+
from matplotlib.text import Annotation
296+
from matplotlib.backends.backend_agg import RendererAgg
297+
298+
figure = Figure(dpi=100)
299+
figure.set_figwidth(2.0)
300+
figure.set_figheight(2.0)
301+
renderer = RendererAgg(200, 200, 100)
302+
303+
# Text annotation with arrow
304+
annotation = Annotation(
305+
'', xy=(0.0, 50.0), xytext=(0.0, 50.0), xycoords='figure pixels')
306+
annotation.set_figure(figure)
307+
annotation.draw(renderer)
308+
309+
bbox = annotation.get_window_extent()
310+
points = bbox.get_points()
311+
312+
eq_(points[0, 0], 0.0)
313+
eq_(points[1, 0], 0.0)
314+
eq_(points[1, 1], 50.0)
315+
eq_(points[0, 1], 50.0)

0 commit comments

Comments
 (0)