|
1 | 1 | """
|
2 |
| -=================== |
3 |
| -Hatches Styles Demo |
4 |
| -=================== |
| 2 | +===================== |
| 3 | +Hatch style reference |
| 4 | +===================== |
5 | 5 |
|
6 | 6 | Hatching (pattern filled polygons) is supported currently in the PS,
|
7 | 7 | PDF, SVG and Agg backends only.
|
|
10 | 10 | import numpy as np
|
11 | 11 | from matplotlib.patches import Rectangle
|
12 | 12 |
|
13 |
| -fig, ax = plt.subplots() |
| 13 | +fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(10, 5)) |
14 | 14 |
|
15 |
| -x = np.repeat([1, 4, 7, 10, 13], 2) |
16 |
| -y = np.tile([2, 5], 5) |
| 15 | +hatches = ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'] |
17 | 16 |
|
18 |
| -pos = np.column_stack((x, y)) |
19 |
| -text_pos = pos + [0.9, -0.5] |
20 | 17 |
|
21 |
| -hashes = ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'] |
| 18 | +def hatches_plot(ax, h): |
| 19 | + ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h)) |
| 20 | + ax.set_title(f"' {h} '") |
| 21 | + ax.axis('equal') |
| 22 | + ax.axis('off') |
22 | 23 |
|
23 |
| -for h, p, t in zip(hashes, pos, text_pos): |
24 |
| - ax.add_patch(Rectangle(p, 2, 2, fill=False, hatch=h)) |
25 |
| - ax.text(t[0], t[1], h, fontsize=15) |
26 |
| - |
27 |
| -ax.axis('equal') |
28 |
| -ax.axis('off') |
29 |
| -fig.tight_layout() |
30 |
| - |
31 |
| -plt.show() |
| 24 | +for ax, h in zip(axs.flat, hatches): |
| 25 | + hatches_plot(ax, h) |
32 | 26 |
|
33 | 27 | #############################################################################
|
34 | 28 | #
|
|
0 commit comments