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

Skip to content

Commit a79ae37

Browse files
authored
DOC: Simplify annotation arrow style reference (#29755)
Position everything in data coordiates rather than Axes coordinates. While the code annotate() is not the primary goal of this example, it's slightly simpler to follow if we keep everything in data coordinates, which is what all the commands (plot, text, annotate) are by default in. The output is basically unchanged, with the exception of making the point marker and the textbox edge dark grey so that the black annotation line stands out more.
1 parent e4e85e6 commit a79ae37

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

galleries/examples/text_labels_and_annotations/fancyarrow_demo.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,31 @@
1919
nrow = (len(styles) + 1) // ncol
2020
axs = (plt.figure(figsize=(4 * ncol, 1 + nrow))
2121
.add_gridspec(1 + nrow, ncol,
22-
wspace=.7, left=.1, right=.9, bottom=0, top=1).subplots())
22+
wspace=0, hspace=0, left=0, right=1, bottom=0, top=1).subplots())
2323
for ax in axs.flat:
24+
ax.set_xlim(-0.5, 4)
2425
ax.set_axis_off()
2526
for ax in axs[0, :]:
26-
ax.text(0, .5, "arrowstyle",
27-
transform=ax.transAxes, size="large", color="tab:blue",
28-
horizontalalignment="center", verticalalignment="center")
29-
ax.text(.35, .5, "default parameters",
30-
transform=ax.transAxes,
31-
horizontalalignment="left", verticalalignment="center")
27+
ax.text(-0.25, 0.5, "arrowstyle", size="large", color="tab:blue")
28+
ax.text(1.25, .5, "default parameters", size="large")
3229
for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):
33-
l, = ax.plot(.25, .5, "ok", transform=ax.transAxes)
34-
ax.annotate(stylename, (.25, .5), (-0.1, .5),
35-
xycoords="axes fraction", textcoords="axes fraction",
36-
size="large", color="tab:blue",
37-
horizontalalignment="center", verticalalignment="center",
30+
# draw dot and annotation with arrowstyle
31+
l, = ax.plot(1, 0, "o", color="grey")
32+
ax.annotate(stylename, (1, 0), (0, 0),
33+
size="large", color="tab:blue", ha="center", va="center",
3834
arrowprops=dict(
3935
arrowstyle=stylename, connectionstyle="arc3,rad=-0.05",
4036
color="k", shrinkA=5, shrinkB=5, patchB=l,
4137
),
42-
bbox=dict(boxstyle="square", fc="w"))
38+
bbox=dict(boxstyle="square", fc="w", ec="grey"))
39+
# draw default parameters
4340
# wrap at every nth comma (n = 1 or 2, depending on text length)
4441
s = str(inspect.signature(stylecls))[1:-1]
4542
n = 2 if s.count(',') > 3 else 1
46-
ax.text(.35, .5,
43+
ax.text(1.25, 0,
4744
re.sub(', ', lambda m, c=itertools.count(1): m.group()
4845
if next(c) % n else '\n', s),
49-
transform=ax.transAxes,
50-
horizontalalignment="left", verticalalignment="center")
46+
verticalalignment="center")
5147

5248
plt.show()
5349

0 commit comments

Comments
 (0)