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 , 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' ,
@@ -378,3 +379,59 @@ def test_packers(align):
378
379
x_height = (x2 - x1 ) / 2
379
380
# x-offsets, y-offsets
380
381
assert_allclose ([(x_height , 0 ), (0 , - y2 )], offset_pairs )
382
+
383
+
384
+ def test_annotationbbox_properties ():
385
+ ab = AnnotationBbox (DrawingArea (20 , 20 , 0 , 0 , clip = True ), (0.5 , 0.5 ),
386
+ xycoords = 'data' )
387
+ assert ab .xyann == (0.5 , 0.5 ) # xy if xybox not given
388
+ assert ab .anncoords == 'data' # xycoords if boxcoords not given
389
+
390
+ ab = AnnotationBbox (DrawingArea (20 , 20 , 0 , 0 , clip = True ), (0.5 , 0.5 ),
391
+ xybox = (- 0.2 , 0.4 ), xycoords = 'data' ,
392
+ boxcoords = 'axes fraction' )
393
+ assert ab .xyann == (- 0.2 , 0.4 ) # xybox if given
394
+ assert ab .anncoords == 'axes fraction' # boxcoords if given
395
+
396
+
397
+ def test_textarea_properties ():
398
+ ta = TextArea ('Foo' )
399
+ assert ta .get_text () == 'Foo'
400
+ assert not ta .get_multilinebaseline ()
401
+
402
+ ta .set_text ('Bar' )
403
+ ta .set_multilinebaseline (True )
404
+ assert ta .get_text () == 'Bar'
405
+ assert ta .get_multilinebaseline ()
406
+
407
+
408
+ @check_figures_equal ()
409
+ def test_textarea_set_text (fig_test , fig_ref ):
410
+ ax_ref = fig_ref .add_subplot ()
411
+ text0 = AnchoredText ("Foo" , "upper left" )
412
+ ax_ref .add_artist (text0 )
413
+
414
+ ax_test = fig_test .add_subplot ()
415
+ text1 = AnchoredText ("Bar" , "upper left" )
416
+ ax_test .add_artist (text1 )
417
+ text1 .txt .set_text ("Foo" )
418
+
419
+
420
+ @image_comparison (['paddedbox.png' ], remove_text = True , style = 'mpl20' )
421
+ def test_paddedbox ():
422
+ fig , ax = plt .subplots ()
423
+
424
+ ta = TextArea ("foo" )
425
+ pb = PaddedBox (ta , pad = 5 , patch_attrs = {'facecolor' : 'r' }, draw_frame = True )
426
+ ab = AnchoredOffsetbox ('upper left' , child = pb )
427
+ ax .add_artist (ab )
428
+
429
+ ta = TextArea ("bar" )
430
+ pb = PaddedBox (ta , pad = 10 , patch_attrs = {'facecolor' : 'b' })
431
+ ab = AnchoredOffsetbox ('upper right' , child = pb )
432
+ ax .add_artist (ab )
433
+
434
+ ta = TextArea ("foobar" )
435
+ pb = PaddedBox (ta , pad = 15 , draw_frame = True )
436
+ ab = AnchoredOffsetbox ('lower right' , child = pb )
437
+ ax .add_artist (ab )
0 commit comments