|
6 | 6 | Overview of the arrow styles available in `~.Axes.annotate`.
|
7 | 7 | """
|
8 | 8 |
|
| 9 | +import inspect |
| 10 | + |
9 | 11 | import matplotlib.patches as mpatches
|
10 | 12 | import matplotlib.pyplot as plt
|
11 | 13 |
|
12 | 14 | styles = mpatches.ArrowStyle.get_styles()
|
13 |
| - |
14 | 15 | ncol = 2
|
15 | 16 | nrow = (len(styles) + 1) // ncol
|
16 |
| -figheight = (nrow + 0.5) |
17 |
| -fig = plt.figure(figsize=(4 * ncol / 1.5, figheight / 1.5)) |
18 |
| -fontsize = 0.2 * 70 |
19 |
| - |
20 |
| -ax = fig.add_axes([0, 0, 1, 1], frameon=False) |
21 |
| -ax.set(xlim=(0, 4 * ncol), ylim=(0, figheight)) |
22 |
| - |
23 |
| -for i, (stylename, styleclass) in enumerate(styles.items()): |
24 |
| - x = 3.2 + (i // nrow) * 4 |
25 |
| - y = (figheight - 0.7 - i % nrow) # /figheight |
26 |
| - p = mpatches.Circle((x, y), 0.2) |
27 |
| - ax.add_patch(p) |
28 |
| - |
29 |
| - ax.annotate(stylename, (x, y), |
30 |
| - (x - 1.2, y), |
31 |
| - ha="right", va="center", |
32 |
| - size=fontsize, |
33 |
| - arrowprops=dict(arrowstyle=stylename, |
34 |
| - patchB=p, |
35 |
| - shrinkA=5, |
36 |
| - shrinkB=5, |
37 |
| - fc="k", ec="k", |
38 |
| - connectionstyle="arc3,rad=-0.05", |
39 |
| - ), |
| 17 | +axs = plt.figure( |
| 18 | + figsize=(4 * ncol, nrow), constrained_layout=True).subplots(nrow, ncol) |
| 19 | +for ax in axs.flat: |
| 20 | + ax.set_axis_off() |
| 21 | +for ax, (stylename, stylecls) in zip(axs.T.flat, styles.items()): |
| 22 | + l, = ax.plot(.8, .5, "o", transform=ax.transAxes) |
| 23 | + ax.annotate(stylename, (.8, .5), (.4, .5), |
| 24 | + xycoords="axes fraction", textcoords="axes fraction", |
| 25 | + horizontalalignment="left", verticalalignment="center", |
| 26 | + arrowprops=dict( |
| 27 | + arrowstyle=stylename, connectionstyle="arc3,rad=-0.05", |
| 28 | + color="k", shrinkA=5, shrinkB=5, patchB=l, |
| 29 | + ), |
40 | 30 | bbox=dict(boxstyle="square", fc="w"))
|
| 31 | + ax.text(.35, .5, |
| 32 | + str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"), |
| 33 | + transform=ax.transAxes, |
| 34 | + horizontalalignment="right", verticalalignment="center") |
41 | 35 |
|
42 | 36 | plt.show()
|
43 | 37 |
|
|
0 commit comments