5
5
from numpy .testing import assert_allclose
6
6
import pytest
7
7
8
- from matplotlib .testing .decorators import image_comparison
8
+ from matplotlib .testing .decorators import check_figures_equal , image_comparison
9
9
import matplotlib .pyplot as plt
10
10
import matplotlib .patches as mpatches
11
11
import matplotlib .lines as mlines
12
12
from matplotlib .backend_bases import MouseButton ,MouseEvent
13
13
14
14
from matplotlib .offsetbox import (
15
- AnchoredOffsetbox ,AnnotationBbox ,AnchoredText ,DrawingArea ,OffsetBox ,
16
- OffsetImage ,PaddedBox ,TextArea ,_get_packed_offsets , HPacker , VPacker )
15
+ AnchoredOffsetbox ,AnnotationBbox ,AnchoredText ,DrawingArea ,HPacker ,
16
+ OffsetBox , OffsetImage ,PaddedBox ,TextArea ,VPacker , _get_packed_offsets )
17
17
18
18
19
19
@image_comparison (['offsetbox_clipping' ],remove_text = True )
@@ -28,6 +28,7 @@ def test_offsetbox_clipping():
28
28
fig ,ax = plt .subplots ()
29
29
size = 100
30
30
da = DrawingArea (size ,size ,clip = True )
31
+ assert da .clip_children
31
32
bg = mpatches .Rectangle ((0 ,0 ),size ,size ,
32
33
facecolor = '#CCCCCC' ,
33
34
edgecolor = 'None' ,
@@ -386,10 +387,66 @@ def test_packers(align):
386
387
[(px + x_height ,py ), (px ,py - y2 )])
387
388
388
389
389
- def test_paddedbox ():
390
+ def test_paddedbox_default_values ():
390
391
# smoke test paddedbox for correct default value
391
392
fig ,ax = plt .subplots ()
392
393
at = AnchoredText ("foo" ,'upper left' )
393
394
pb = PaddedBox (at ,patch_attrs = {'facecolor' :'r' },draw_frame = True )
394
395
ax .add_artist (pb )
395
396
fig .draw_without_rendering ()
397
+
398
+
399
+ def test_annotationbbox_properties ():
400
+ ab = AnnotationBbox (DrawingArea (20 ,20 ,0 ,0 ,clip = True ), (0.5 ,0.5 ),
401
+ xycoords = 'data' )
402
+ assert ab .xyann == (0.5 ,0.5 )# xy if xybox not given
403
+ assert ab .anncoords == 'data' # xycoords if boxcoords not given
404
+
405
+ ab = AnnotationBbox (DrawingArea (20 ,20 ,0 ,0 ,clip = True ), (0.5 ,0.5 ),
406
+ xybox = (- 0.2 ,0.4 ),xycoords = 'data' ,
407
+ boxcoords = 'axes fraction' )
408
+ assert ab .xyann == (- 0.2 ,0.4 )# xybox if given
409
+ assert ab .anncoords == 'axes fraction' # boxcoords if given
410
+
411
+
412
+ def test_textarea_properties ():
413
+ ta = TextArea ('Foo' )
414
+ assert ta .get_text ()== 'Foo'
415
+ assert not ta .get_multilinebaseline ()
416
+
417
+ ta .set_text ('Bar' )
418
+ ta .set_multilinebaseline (True )
419
+ assert ta .get_text ()== 'Bar'
420
+ assert ta .get_multilinebaseline ()
421
+
422
+
423
+ @check_figures_equal ()
424
+ def test_textarea_set_text (fig_test ,fig_ref ):
425
+ ax_ref = fig_ref .add_subplot ()
426
+ text0 = AnchoredText ("Foo" ,"upper left" )
427
+ ax_ref .add_artist (text0 )
428
+
429
+ ax_test = fig_test .add_subplot ()
430
+ text1 = AnchoredText ("Bar" ,"upper left" )
431
+ ax_test .add_artist (text1 )
432
+ text1 .txt .set_text ("Foo" )
433
+
434
+
435
+ @image_comparison (['paddedbox.png' ],remove_text = True ,style = 'mpl20' )
436
+ def test_paddedbox ():
437
+ fig ,ax = plt .subplots ()
438
+
439
+ ta = TextArea ("foo" )
440
+ pb = PaddedBox (ta ,pad = 5 ,patch_attrs = {'facecolor' :'r' },draw_frame = True )
441
+ ab = AnchoredOffsetbox ('upper left' ,child = pb )
442
+ ax .add_artist (ab )
443
+
444
+ ta = TextArea ("bar" )
445
+ pb = PaddedBox (ta ,pad = 10 ,patch_attrs = {'facecolor' :'b' })
446
+ ab = AnchoredOffsetbox ('upper right' ,child = pb )
447
+ ax .add_artist (ab )
448
+
449
+ ta = TextArea ("foobar" )
450
+ pb = PaddedBox (ta ,pad = 15 ,draw_frame = True )
451
+ ab = AnchoredOffsetbox ('lower right' ,child = pb )
452
+ ax .add_artist (ab )