Skip to content

Commit 5ea5c4b

Browse files
committed
Added density and combination hatching examples
1 parent be2e5d7 commit 5ea5c4b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

examples/shapes_and_collections/hatch_style_reference.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,45 @@
99
import matplotlib.pyplot as plt
1010
from matplotlib.patches import Rectangle
1111

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))
1313

1414
hatches = ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']
1515

1616

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+
1751
def hatches_plot(ax, h):
1852
ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h))
1953
ax.text(1, -0.5, f"' {h} '", size=15, ha="center")

0 commit comments

Comments
 (0)