|
22 | 22 |
|
23 | 23 | # Define a 1st position to annotate (display it with a marker)
|
24 | 24 | xy = (0.5, 0.7)
|
25 |
| -ax.plot(xy[0], xy[1], ".r") |
| 25 | +ax.plot(xy[0], xy[1], '.r') |
26 | 26 |
|
27 | 27 | # Annotate the 1st position with a text box ('Test 1')
|
28 |
| -offsetbox = TextArea("Test 1") |
| 28 | +offsetbox = TextArea('Test 1') |
29 | 29 |
|
30 | 30 | ab = AnnotationBbox(offsetbox, xy,
|
31 | 31 | xybox=(-20, 40),
|
32 | 32 | xycoords='data',
|
33 |
| - boxcoords="offset points", |
34 |
| - arrowprops=dict(arrowstyle="->")) |
| 33 | + boxcoords='offset points', |
| 34 | + arrowprops=dict(arrowstyle='->'), |
| 35 | + bboxprops=dict(boxstyle='sawtooth')) |
35 | 36 | ax.add_artist(ab)
|
36 | 37 |
|
37 | 38 | # Annotate the 1st position with another text box ('Test')
|
38 |
| -offsetbox = TextArea("Test") |
| 39 | +offsetbox = TextArea('Test') |
39 | 40 |
|
40 | 41 | ab = AnnotationBbox(offsetbox, xy,
|
41 | 42 | xybox=(1.02, xy[1]),
|
42 | 43 | xycoords='data',
|
43 |
| - boxcoords=("axes fraction", "data"), |
| 44 | + boxcoords=('axes fraction', 'data'), |
44 | 45 | box_alignment=(0., 0.5),
|
45 |
| - arrowprops=dict(arrowstyle="->")) |
| 46 | + arrowprops=dict(arrowstyle='->')) |
46 | 47 | ax.add_artist(ab)
|
47 | 48 |
|
48 | 49 | # Define a 2nd position to annotate (don't display with a marker this time)
|
|
54 | 55 | da.add_artist(p)
|
55 | 56 |
|
56 | 57 | ab = AnnotationBbox(da, xy,
|
57 |
| - xybox=(1.02, xy[1]), |
| 58 | + xybox=(1., xy[1]), |
58 | 59 | 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)) |
62 | 64 |
|
63 | 65 | ax.add_artist(ab)
|
64 | 66 |
|
|
70 | 72 | ab = AnnotationBbox(im, xy,
|
71 | 73 | xybox=(-50., 50.),
|
72 | 74 | xycoords='data',
|
73 |
| - boxcoords="offset points", |
| 75 | + boxcoords='offset points', |
74 | 76 | pad=0.3,
|
75 |
| - arrowprops=dict(arrowstyle="->")) |
| 77 | + arrowprops=dict(arrowstyle='->')) |
76 | 78 |
|
77 | 79 | ax.add_artist(ab)
|
78 | 80 |
|
79 | 81 | # 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: |
81 | 83 | arr_img = plt.imread(file)
|
82 | 84 |
|
83 | 85 | imagebox = OffsetImage(arr_img, zoom=0.2)
|
|
86 | 88 | ab = AnnotationBbox(imagebox, xy,
|
87 | 89 | xybox=(120., -80.),
|
88 | 90 | xycoords='data',
|
89 |
| - boxcoords="offset points", |
| 91 | + boxcoords='offset points', |
90 | 92 | pad=0.5,
|
91 | 93 | arrowprops=dict(
|
92 |
| - arrowstyle="->", |
93 |
| - connectionstyle="angle,angleA=0,angleB=90,rad=3") |
| 94 | + arrowstyle='->', |
| 95 | + connectionstyle='angle,angleA=0,angleB=90,rad=3') |
94 | 96 | )
|
95 | 97 |
|
96 | 98 | ax.add_artist(ab)
|
|
0 commit comments