|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 | from matplotlib.patches import Rectangle
|
11 | 11 |
|
12 |
| -fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(10, 5)) |
| 12 | +fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(9, 4.5)) |
13 | 13 |
|
14 | 14 | hatches = ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']
|
15 | 15 |
|
16 | 16 |
|
| 17 | +def hatches_plot(ax, h): |
| 18 | + ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h)) |
| 19 | + ax.text(1, -0.5, f"' {h} '", size=15, ha="center") |
| 20 | + ax.axis('equal') |
| 21 | + ax.axis('off') |
| 22 | + |
| 23 | +for ax, h in zip(axs.flat, hatches): |
| 24 | + hatches_plot(ax, h) |
| 25 | + |
| 26 | +############################################################################### |
| 27 | +# Hatching patterns can be repeated to increase the density. |
| 28 | + |
| 29 | +fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(9, 4.5)) |
| 30 | + |
| 31 | +hatches = ['//', '\\\\', '||', '--', '++', 'xx', 'oo', 'OO', '..', '**'] |
| 32 | + |
| 33 | + |
| 34 | +def hatches_plot(ax, h): |
| 35 | + ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h)) |
| 36 | + ax.text(1, -0.5, f"' {h} '", size=15, ha="center") |
| 37 | + ax.axis('equal') |
| 38 | + ax.axis('off') |
| 39 | + |
| 40 | +for ax, h in zip(axs.flat, hatches): |
| 41 | + hatches_plot(ax, h) |
| 42 | + |
| 43 | +############################################################################### |
| 44 | +# Hatching patterns can be combined to create additional patterns. |
| 45 | + |
| 46 | +fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(9, 4.5)) |
| 47 | + |
| 48 | +hatches = ['//', '\\\\', '||', '--', '++', 'xx', 'oo', 'OO', '..', '**'] |
| 49 | + |
| 50 | + |
17 | 51 | def hatches_plot(ax, h):
|
18 | 52 | ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h))
|
19 | 53 | ax.text(1, -0.5, f"' {h} '", size=15, ha="center")
|
|
0 commit comments