|
7 | 7 | """
|
8 | 8 |
|
9 | 9 | import inspect
|
| 10 | +import re |
| 11 | +import itertools |
10 | 12 |
|
11 | 13 | import matplotlib.patches as mpatches
|
12 | 14 | import matplotlib.pyplot as plt
|
|
16 | 18 | nrow = (len(styles) + 1) // ncol
|
17 | 19 | axs = (plt.figure(figsize=(4 * ncol, 1 + nrow))
|
18 | 20 | .add_gridspec(1 + nrow, ncol,
|
19 |
| - wspace=.5, left=.1, right=.9, bottom=0, top=1).subplots()) |
| 21 | + wspace=.7, left=.1, right=.9, bottom=0, top=1).subplots()) |
20 | 22 | for ax in axs.flat:
|
21 | 23 | ax.set_axis_off()
|
22 | 24 | for ax in axs[0, :]:
|
23 | 25 | ax.text(0, .5, "arrowstyle",
|
24 | 26 | transform=ax.transAxes, size="large", color="tab:blue",
|
25 | 27 | horizontalalignment="center", verticalalignment="center")
|
26 |
| - ax.text(.5, .5, "default parameters", |
| 28 | + ax.text(.35, .5, "default parameters", |
27 | 29 | transform=ax.transAxes,
|
28 | 30 | horizontalalignment="left", verticalalignment="center")
|
29 | 31 | 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 | + l, = ax.plot(.25, .5, "ok", transform=ax.transAxes) |
| 33 | + ax.annotate(stylename, (.25, .5), (-0.1, .5), |
32 | 34 | xycoords="axes fraction", textcoords="axes fraction",
|
33 | 35 | size="large", color="tab:blue",
|
34 | 36 | horizontalalignment="center", verticalalignment="center",
|
|
37 | 39 | color="k", shrinkA=5, shrinkB=5, patchB=l,
|
38 | 40 | ),
|
39 | 41 | bbox=dict(boxstyle="square", fc="w"))
|
40 |
| - ax.text(.5, .5, |
41 |
| - str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"), |
| 42 | + # wrap at every nth comma (n = 1 or 2, depending on text length) |
| 43 | + s = str(inspect.signature(stylecls))[1:-1] |
| 44 | + n = 2 if s.count(',') > 3 else 1 |
| 45 | + ax.text(.35, .5, |
| 46 | + re.sub(', ', lambda m, c=itertools.count(1): m.group() |
| 47 | + if next(c) % n else '\n', s), |
42 | 48 | transform=ax.transAxes,
|
43 | 49 | horizontalalignment="left", verticalalignment="center")
|
44 | 50 |
|
|
0 commit comments