|
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(figsize=(4 * ncol, 1 + nrow)) |
| 18 | + .add_gridspec(1 + nrow, ncol, |
| 19 | + wspace=.5, left=.1, right=.9, bottom=0, top=1).subplots()) |
| 20 | +for ax in axs.flat: |
| 21 | + ax.set_axis_off() |
| 22 | +for ax in axs[0, :]: |
| 23 | + ax.text(0, .5, "arrowstyle", |
| 24 | + transform=ax.transAxes, size="large", color="tab:blue", |
| 25 | + horizontalalignment="center", verticalalignment="center") |
| 26 | + ax.text(.5, .5, "default parameters", |
| 27 | + transform=ax.transAxes, |
| 28 | + horizontalalignment="left", verticalalignment="center") |
| 29 | +for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()): |
| 30 | + l, = ax.plot(.35, .5, "ok", transform=ax.transAxes) |
| 31 | + ax.annotate(stylename, (.35, .5), (0, .5), |
| 32 | + xycoords="axes fraction", textcoords="axes fraction", |
| 33 | + size="large", color="tab:blue", |
| 34 | + horizontalalignment="center", verticalalignment="center", |
| 35 | + arrowprops=dict( |
| 36 | + arrowstyle=stylename, connectionstyle="arc3,rad=-0.05", |
| 37 | + color="k", shrinkA=5, shrinkB=5, patchB=l, |
| 38 | + ), |
40 | 39 | bbox=dict(boxstyle="square", fc="w"))
|
| 40 | + ax.text(.5, .5, |
| 41 | + str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"), |
| 42 | + transform=ax.transAxes, |
| 43 | + horizontalalignment="left", verticalalignment="center") |
41 | 44 |
|
42 | 45 | plt.show()
|
43 | 46 |
|
|
0 commit comments