Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78307ab

Browse files
committed
DOC: describe bboxprops for AnnotationBbox
1 parent d95edc4 commit 78307ab

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

examples/text_labels_and_annotations/demo_annotation_box.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,28 @@
2222

2323
# Define a 1st position to annotate (display it with a marker)
2424
xy = (0.5, 0.7)
25-
ax.plot(xy[0], xy[1], ".r")
25+
ax.plot(xy[0], xy[1], '.r')
2626

2727
# Annotate the 1st position with a text box ('Test 1')
28-
offsetbox = TextArea("Test 1")
28+
offsetbox = TextArea('Test 1')
2929

3030
ab = AnnotationBbox(offsetbox, xy,
3131
xybox=(-20, 40),
3232
xycoords='data',
33-
boxcoords="offset points",
34-
arrowprops=dict(arrowstyle="->"))
33+
boxcoords='offset points',
34+
arrowprops=dict(arrowstyle='->'),
35+
bboxprops=dict(boxstyle='sawtooth'))
3536
ax.add_artist(ab)
3637

3738
# Annotate the 1st position with another text box ('Test')
38-
offsetbox = TextArea("Test")
39+
offsetbox = TextArea('Test')
3940

4041
ab = AnnotationBbox(offsetbox, xy,
4142
xybox=(1.02, xy[1]),
4243
xycoords='data',
43-
boxcoords=("axes fraction", "data"),
44+
boxcoords=('axes fraction', 'data'),
4445
box_alignment=(0., 0.5),
45-
arrowprops=dict(arrowstyle="->"))
46+
arrowprops=dict(arrowstyle='->'))
4647
ax.add_artist(ab)
4748

4849
# Define a 2nd position to annotate (don't display with a marker this time)
@@ -54,11 +55,12 @@
5455
da.add_artist(p)
5556

5657
ab = AnnotationBbox(da, xy,
57-
xybox=(1.02, xy[1]),
58+
xybox=(1., xy[1]),
5859
xycoords='data',
59-
boxcoords=("axes fraction", "data"),
60-
box_alignment=(0., 0.5),
61-
arrowprops=dict(arrowstyle="->"))
60+
boxcoords=('axes fraction', 'data'),
61+
box_alignment=(0.2, 0.5),
62+
arrowprops=dict(arrowstyle='->'),
63+
bboxprops=dict(alpha=0.5))
6264

6365
ax.add_artist(ab)
6466

@@ -70,14 +72,14 @@
7072
ab = AnnotationBbox(im, xy,
7173
xybox=(-50., 50.),
7274
xycoords='data',
73-
boxcoords="offset points",
75+
boxcoords='offset points',
7476
pad=0.3,
75-
arrowprops=dict(arrowstyle="->"))
77+
arrowprops=dict(arrowstyle='->'))
7678

7779
ax.add_artist(ab)
7880

7981
# Annotate the 2nd position with another image (a Grace Hopper portrait)
80-
with get_sample_data("grace_hopper.jpg") as file:
82+
with get_sample_data('grace_hopper.jpg') as file:
8183
arr_img = plt.imread(file)
8284

8385
imagebox = OffsetImage(arr_img, zoom=0.2)
@@ -86,11 +88,11 @@
8688
ab = AnnotationBbox(imagebox, xy,
8789
xybox=(120., -80.),
8890
xycoords='data',
89-
boxcoords="offset points",
91+
boxcoords='offset points',
9092
pad=0.5,
9193
arrowprops=dict(
92-
arrowstyle="->",
93-
connectionstyle="angle,angleA=0,angleB=90,rad=3")
94+
arrowstyle='->',
95+
connectionstyle='angle,angleA=0,angleB=90,rad=3')
9496
)
9597

9698
ax.add_artist(ab)

lib/matplotlib/offsetbox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,11 @@ def __init__(self, offsetbox, xy,
12701270
the offset box w.r.t. the *boxcoords*.
12711271
The lower-left corner is (0, 0) and upper-right corner is (1, 1).
12721272
1273+
bboxprops : dict, optional
1274+
A dictionary of properties to set for the annotation bounding box,
1275+
for example *boxstyle* and *alpha*. See `.FancyBboxPatch` for
1276+
details.
1277+
12731278
**kwargs
12741279
Other parameters are identical to `.Annotation`.
12751280
"""

0 commit comments

Comments
 (0)