|
3 | 3 | Annotation arrow style reference
|
4 | 4 | ================================
|
5 | 5 |
|
6 |
| -Overview of the arrow styles available in `~.Axes.annotate`. |
| 6 | +Overview of the available `.ArrowStyle` settings. These are used for the *arrowstyle* |
| 7 | +parameter of `~.Axes.annotate` and `.FancyArrowPatch`. |
| 8 | +
|
| 9 | +Each style can be configured with a set of parameters, which are stated along with |
| 10 | +their default values. |
7 | 11 | """
|
8 | 12 |
|
9 | 13 | importinspect
|
|
12 | 16 |
|
13 | 17 | importmatplotlib.pyplotasplt
|
14 | 18 |
|
15 |
| -importmatplotlib.patchesasmpatches |
| 19 | +frommatplotlib.patchesimportArrowStyle |
16 | 20 |
|
17 |
| -styles=mpatches.ArrowStyle.get_styles() |
| 21 | +styles=ArrowStyle.get_styles() |
18 | 22 | ncol=2
|
19 | 23 | nrow= (len(styles)+1)//ncol
|
20 |
| -axs=(plt.figure(figsize=(4*ncol,1+nrow)) |
21 |
| - .add_gridspec(1+nrow,ncol, |
22 |
| -wspace=0,hspace=0,left=0,right=1,bottom=0,top=1).subplots()) |
| 24 | +gridspec_kw=dict(wspace=0,hspace=0.05,left=0,right=1,bottom=0,top=1) |
| 25 | +fig,axs=plt.subplots(1+nrow,ncol, |
| 26 | +figsize=(4*ncol,1+nrow),gridspec_kw=gridspec_kw) |
23 | 27 | foraxinaxs.flat:
|
24 |
| -ax.set_xlim(-0.5,4) |
| 28 | +ax.set_xlim(-0.1,4) |
25 | 29 | ax.set_axis_off()
|
26 | 30 | foraxinaxs[0, :]:
|
27 |
| -ax.text(-0.25,0.5,"arrowstyle",size="large",color="tab:blue") |
28 |
| -ax.text(1.25,.5,"default parameters",size="large") |
| 31 | +ax.text(0,0.5,"arrowstyle",size="large",color="tab:blue") |
| 32 | +ax.text(1.4,.5,"default parameters",size="large") |
29 | 33 | forax, (stylename,stylecls)inzip(axs[1:, :].T.flat,styles.items()):
|
30 | 34 | # 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", |
| 35 | +l,=ax.plot(1.25,0,"o",color="darkgrey") |
| 36 | +ax.annotate(stylename, (1.25,0), (0,0), |
| 37 | +size="large",color="tab:blue",va="center",family="monospace", |
34 | 38 | arrowprops=dict(
|
35 |
| -arrowstyle=stylename,connectionstyle="arc3,rad=-0.05", |
36 |
| -color="k",shrinkA=5,shrinkB=5,patchB=l, |
| 39 | +arrowstyle=stylename,connectionstyle="arc3,rad=0", |
| 40 | +color="black",shrinkA=5,shrinkB=5,patchB=l, |
37 | 41 | ),
|
38 |
| -bbox=dict(boxstyle="square",fc="w",ec="grey")) |
| 42 | +bbox=dict(boxstyle="square",fc="w",ec="darkgrey")) |
39 | 43 | # draw default parameters
|
40 | 44 | # wrap at every nth comma (n = 1 or 2, depending on text length)
|
41 | 45 | s=str(inspect.signature(stylecls))[1:-1]
|
42 | 46 | n=2ifs.count(',')>3else1
|
43 |
| -ax.text(1.25,0, |
| 47 | +ax.text(1.4,0, |
44 | 48 | re.sub(', ',lambdam,c=itertools.count(1):m.group()
|
45 | 49 | ifnext(c)%nelse'\n',s),
|
46 |
| -verticalalignment="center") |
| 50 | +verticalalignment="center",color="0.3") |
47 | 51 |
|
48 | 52 | plt.show()
|
49 | 53 |
|
|