|
8 | 8 | from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 | 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_ |
12 | 13 |
|
13 | 14 |
|
14 | 15 | @image_comparison(baseline_images=['font_styles'])
|
@@ -260,3 +261,55 @@ def test_annotation_negative_coords():
|
260 | 261 | ax.annotate("-fpx", (-45, -30), xycoords="figure pixels")
|
261 | 262 | ax.annotate("-apt", (-35, -20), xycoords="axes points")
|
262 | 263 | 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