(extent_kind)
| 259 | |
| 260 | @pytest.mark.parametrize("extent_kind", ["window_extent", "tightbbox"]) |
| 261 | def test_annotationbbox_extents(extent_kind): |
| 262 | plt.rcParams.update(plt.rcParamsDefault) |
| 263 | fig, ax = plt.subplots(figsize=(4, 3), dpi=100) |
| 264 | |
| 265 | ax.axis([0, 1, 0, 1]) |
| 266 | |
| 267 | an1 = ax.annotate("Annotation", xy=(.9, .9), xytext=(1.1, 1.1), |
| 268 | arrowprops=dict(arrowstyle="->"), clip_on=False, |
| 269 | va="baseline", ha="left") |
| 270 | |
| 271 | da = DrawingArea(20, 20, 0, 0, clip=True) |
| 272 | p = mpatches.Circle((-10, 30), 32) |
| 273 | da.add_artist(p) |
| 274 | |
| 275 | ab3 = AnnotationBbox(da, [.5, .5], xybox=(-0.2, 0.5), xycoords='data', |
| 276 | boxcoords="axes fraction", box_alignment=(0., .5), |
| 277 | arrowprops=dict(arrowstyle="->")) |
| 278 | ax.add_artist(ab3) |
| 279 | |
| 280 | im = OffsetImage(np.random.rand(10, 10), zoom=3) |
| 281 | im.image.axes = ax |
| 282 | ab6 = AnnotationBbox(im, (0.5, -.3), xybox=(0, 75), |
| 283 | xycoords='axes fraction', |
| 284 | boxcoords="offset points", pad=0.3, |
| 285 | arrowprops=dict(arrowstyle="->")) |
| 286 | ax.add_artist(ab6) |
| 287 | |
| 288 | # Test Annotation |
| 289 | bb1 = getattr(an1, f"get_{extent_kind}")() |
| 290 | |
| 291 | target1 = [332.9, 242.8, 467.0, 298.9] |
| 292 | assert_allclose(bb1.extents, target1, atol=2) |
| 293 | |
| 294 | # Test AnnotationBbox |
| 295 | bb3 = getattr(ab3, f"get_{extent_kind}")() |
| 296 | |
| 297 | target3 = [-17.6, 129.0, 200.7, 167.9] |
| 298 | assert_allclose(bb3.extents, target3, atol=2) |
| 299 | |
| 300 | bb6 = getattr(ab6, f"get_{extent_kind}")() |
| 301 | |
| 302 | target6 = [180.0, -32.0, 230.0, 92.9] |
| 303 | assert_allclose(bb6.extents, target6, atol=2) |
| 304 | |
| 305 | # Test bbox_inches='tight' |
| 306 | buf = io.BytesIO() |
| 307 | fig.savefig(buf, bbox_inches='tight') |
| 308 | buf.seek(0) |
| 309 | shape = plt.imread(buf).shape |
| 310 | targetshape = (350, 504, 4) |
| 311 | assert_allclose(shape, targetshape, atol=2) |
| 312 | |
| 313 | # Simple smoke test for tight_layout, to make sure it does not error out. |
| 314 | fig.canvas.draw() |
| 315 | fig.tight_layout() |
| 316 | fig.canvas.draw() |
| 317 | |
| 318 |
nothing calls this directly
no test coverage detected
searching dependent graphs…