@@ -305,177 +305,8 @@ def test_get_rotation_mod360():
305
305
for i , j in zip ([360. , 377. , 720 + 177.2 ], [0. , 17. , 177.2 ]):
306
306
assert_almost_equal (text .get_rotation (i ), j )
307
307
308
-
309
308
@image_comparison (baseline_images = ['text_bboxclip' ])
310
309
def test_bbox_clipping ():
311
310
plt .text (0.9 , 0.2 , 'Is bbox clipped?' , backgroundcolor = 'r' , clip_on = True )
312
311
t = plt .text (0.9 , 0.5 , 'Is fancy bbox clipped?' , clip_on = True )
313
312
t .set_bbox ({"boxstyle" : "round, pad=0.1" })
314
-
315
-
316
- @image_comparison (baseline_images = ['annotation_negative_coords' ],
317
- extensions = ['png' ])
318
- def test_annotation_negative_coords ():
319
- fig = plt .figure ()
320
- ax = plt .subplot (1 , 1 , 1 )
321
-
322
- ax .annotate ("+fpt" , (15 , 40 ), xycoords = "figure points" )
323
- ax .annotate ("+fpx" , (25 , 30 ), xycoords = "figure pixels" )
324
- ax .annotate ("+apt" , (35 , 20 ), xycoords = "axes points" )
325
- ax .annotate ("+apx" , (45 , 10 ), xycoords = "axes pixels" )
326
-
327
- ax .annotate ("-fpt" , (- 55 , - 40 ), xycoords = "figure points" )
328
- ax .annotate ("-fpx" , (- 45 , - 30 ), xycoords = "figure pixels" )
329
- ax .annotate ("-apt" , (- 35 , - 20 ), xycoords = "axes points" )
330
- ax .annotate ("-apx" , (- 25 , - 10 ), xycoords = "axes pixels" )
331
-
332
-
333
- @cleanup
334
- def test_text_annotation_get_window_extent ():
335
- figure = Figure (dpi = 100 )
336
- renderer = RendererAgg (200 , 200 , 100 )
337
-
338
- # Only text annotation
339
- annotation = Annotation ('test' , xy = (0 , 0 ))
340
- annotation .set_figure (figure )
341
-
342
- text = Text (text = 'test' , x = 0 , y = 0 )
343
- text .set_figure (figure )
344
-
345
- bbox = annotation .get_window_extent (renderer = renderer )
346
-
347
- text_bbox = text .get_window_extent (renderer = renderer )
348
- eq_ (bbox .width , text_bbox .width )
349
- eq_ (bbox .height , text_bbox .height )
350
-
351
- _ , _ , d = renderer .get_text_width_height_descent (
352
- 'text' , annotation ._fontproperties , ismath = False )
353
- _ , _ , lp_d = renderer .get_text_width_height_descent (
354
- 'lp' , annotation ._fontproperties , ismath = False )
355
- below_line = max (d , lp_d )
356
-
357
- # These numbers are specific to the current implementation of Text
358
- points = bbox .get_points ()
359
- eq_ (points [0 , 0 ], 0.0 )
360
- eq_ (points [1 , 0 ], text_bbox .width )
361
- eq_ (points [0 , 1 ], - below_line )
362
- eq_ (points [1 , 1 ], text_bbox .height - below_line )
363
-
364
-
365
- @cleanup
366
- def test_text_with_arrow_annotation_get_window_extent ():
367
- headwidth = 21
368
- fig , ax = plt .subplots (dpi = 100 )
369
- txt = ax .text (s = 'test' , x = 0 , y = 0 )
370
- ann = ax .annotate (
371
- 'test' ,
372
- xy = (0.0 , 50.0 ),
373
- xytext = (50.0 , 50.0 ), xycoords = 'figure pixels' ,
374
- arrowprops = {
375
- 'facecolor' : 'black' , 'width' : 2 ,
376
- 'headwidth' : headwidth , 'shrink' : 0.0 })
377
-
378
- plt .draw ()
379
- renderer = fig .canvas .renderer
380
- # bounding box of text
381
- text_bbox = txt .get_window_extent (renderer = renderer )
382
- # bounding box of annotation (text + arrow)
383
- bbox = ann .get_window_extent (renderer = renderer )
384
- # bounding box of arrow
385
- arrow_bbox = ann .arrow_patch .get_window_extent (renderer )
386
- # bounding box of annotation text
387
- ann_txt_bbox = Text .get_window_extent (ann )
388
-
389
- # make sure annotation width is 50 px wider than
390
- # just the text
391
- eq_ (bbox .width , text_bbox .width + 50.0 )
392
- # make sure the annotation text bounding box is same size
393
- # as the bounding box of the same string as a Text object
394
- eq_ (ann_txt_bbox .height , text_bbox .height )
395
- eq_ (ann_txt_bbox .width , text_bbox .width )
396
- # compute the expected bounding box of arrow + text
397
- expected_bbox = Bbox .union ([ann_txt_bbox , arrow_bbox ])
398
- assert_almost_equal (bbox .height , expected_bbox .height )
399
-
400
-
401
- @cleanup
402
- def test_arrow_annotation_get_window_extent ():
403
- dpi = 100
404
- dots_per_point = dpi / 72
405
- figure = Figure (dpi = dpi )
406
- figure .set_figwidth (2.0 )
407
- figure .set_figheight (2.0 )
408
- renderer = RendererAgg (200 , 200 , 100 )
409
-
410
- # Text annotation with arrow; arrow dimensions are in points
411
- annotation = Annotation (
412
- '' , xy = (0.0 , 50.0 ), xytext = (50.0 , 50.0 ), xycoords = 'figure pixels' ,
413
- arrowprops = {
414
- 'facecolor' : 'black' , 'width' : 8 , 'headwidth' : 10 , 'shrink' : 0.0 })
415
- annotation .set_figure (figure )
416
- annotation .draw (renderer )
417
-
418
- bbox = annotation .get_window_extent ()
419
- points = bbox .get_points ()
420
-
421
- eq_ (bbox .width , 50.0 )
422
- assert_almost_equal (bbox .height , 10.0 * dots_per_point )
423
- eq_ (points [0 , 0 ], 0.0 )
424
- eq_ (points [0 , 1 ], 50.0 - 5 * dots_per_point )
425
-
426
-
427
- @cleanup
428
- def test_empty_annotation_get_window_extent ():
429
- figure = Figure (dpi = 100 )
430
- figure .set_figwidth (2.0 )
431
- figure .set_figheight (2.0 )
432
- renderer = RendererAgg (200 , 200 , 100 )
433
-
434
- # Text annotation with arrow
435
- annotation = Annotation (
436
- '' , xy = (0.0 , 50.0 ), xytext = (0.0 , 50.0 ), xycoords = 'figure pixels' )
437
- annotation .set_figure (figure )
438
- annotation .draw (renderer )
439
-
440
- bbox = annotation .get_window_extent ()
441
- points = bbox .get_points ()
442
-
443
- eq_ (points [0 , 0 ], 0.0 )
444
- eq_ (points [1 , 0 ], 0.0 )
445
- eq_ (points [1 , 1 ], 50.0 )
446
- eq_ (points [0 , 1 ], 50.0 )
447
-
448
-
449
- @image_comparison (baseline_images = ['basictext_wrap' ],
450
- extensions = ['png' ])
451
- def test_basic_wrap ():
452
- fig = plt .figure ()
453
- plt .axis ([0 , 10 , 0 , 10 ])
454
- t = "This is a really long string that I'd rather have wrapped so that" \
455
- " it doesn't go outside of the figure, but if it's long enough it" \
456
- " will go off the top or bottom!"
457
- plt .text (4 , 1 , t , ha = 'left' , rotation = 15 , wrap = True )
458
- plt .text (6 , 5 , t , ha = 'left' , rotation = 15 , wrap = True )
459
- plt .text (5 , 5 , t , ha = 'right' , rotation = - 15 , wrap = True )
460
- plt .text (5 , 10 , t , fontsize = 18 , style = 'oblique' , ha = 'center' ,
461
- va = 'top' , wrap = True )
462
- plt .text (3 , 4 , t , family = 'serif' , style = 'italic' , ha = 'right' , wrap = True )
463
- plt .text (- 1 , 0 , t , ha = 'left' , rotation = - 15 , wrap = True )
464
-
465
-
466
- @image_comparison (baseline_images = ['fonttext_wrap' ],
467
- extensions = ['png' ])
468
- def test_font_wrap ():
469
- fig = plt .figure ()
470
- plt .axis ([0 , 10 , 0 , 10 ])
471
- t = "This is a really long string that I'd rather have wrapped so that" \
472
- " it doesn't go outside of the figure, but if it's long enough it" \
473
- " will go off the top or bottom!"
474
- plt .text (4 , - 1 , t , fontsize = 18 , family = 'serif' , ha = 'left' , rotation = 15 ,
475
- wrap = True )
476
- plt .text (6 , 5 , t , family = 'sans serif' , ha = 'left' , rotation = 15 , wrap = True )
477
- plt .text (5 , 5 , t , weight = 'light' , ha = 'right' , rotation = - 15 , wrap = True )
478
- plt .text (5 , 10 , t , weight = 'heavy' , ha = 'center' , va = 'top' , wrap = True )
479
- plt .text (3 , 4 , t , family = 'monospace' , ha = 'right' , wrap = True )
480
- plt .text (- 1 , 0 , t , fontsize = 14 , style = 'italic' , ha = 'left' , rotation = - 15 ,
481
- wrap = True )
0 commit comments