Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38abc71

Browse files
authored
Merge pull request#24486 from oscargus/offsetboxtests
Minor cleanup and add test for offsetbox
2 parentsa046ee3 +f9e9c34 commit38abc71

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

‎lib/matplotlib/tests/test_offsetbox.py

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
fromnumpy.testingimportassert_allclose
66
importpytest
77

8-
frommatplotlib.testing.decoratorsimportimage_comparison
8+
frommatplotlib.testing.decoratorsimportcheck_figures_equal,image_comparison
99
importmatplotlib.pyplotasplt
1010
importmatplotlib.patchesasmpatches
1111
importmatplotlib.linesasmlines
1212
frommatplotlib.backend_basesimportMouseButton,MouseEvent
1313

1414
frommatplotlib.offsetboximport (
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)
1717

1818

1919
@image_comparison(['offsetbox_clipping'],remove_text=True)
@@ -28,6 +28,7 @@ def test_offsetbox_clipping():
2828
fig,ax=plt.subplots()
2929
size=100
3030
da=DrawingArea(size,size,clip=True)
31+
assertda.clip_children
3132
bg=mpatches.Rectangle((0,0),size,size,
3233
facecolor='#CCCCCC',
3334
edgecolor='None',
@@ -386,10 +387,66 @@ def test_packers(align):
386387
[(px+x_height,py), (px,py-y2)])
387388

388389

389-
deftest_paddedbox():
390+
deftest_paddedbox_default_values():
390391
# smoke test paddedbox for correct default value
391392
fig,ax=plt.subplots()
392393
at=AnchoredText("foo",'upper left')
393394
pb=PaddedBox(at,patch_attrs={'facecolor':'r'},draw_frame=True)
394395
ax.add_artist(pb)
395396
fig.draw_without_rendering()
397+
398+
399+
deftest_annotationbbox_properties():
400+
ab=AnnotationBbox(DrawingArea(20,20,0,0,clip=True), (0.5,0.5),
401+
xycoords='data')
402+
assertab.xyann== (0.5,0.5)# xy if xybox not given
403+
assertab.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+
assertab.xyann== (-0.2,0.4)# xybox if given
409+
assertab.anncoords=='axes fraction'# boxcoords if given
410+
411+
412+
deftest_textarea_properties():
413+
ta=TextArea('Foo')
414+
assertta.get_text()=='Foo'
415+
assertnotta.get_multilinebaseline()
416+
417+
ta.set_text('Bar')
418+
ta.set_multilinebaseline(True)
419+
assertta.get_text()=='Bar'
420+
assertta.get_multilinebaseline()
421+
422+
423+
@check_figures_equal()
424+
deftest_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+
deftest_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)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp