8000 Update hatch demo · matplotlib/matplotlib@9b04f25 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b04f25

Browse files
committed
Update hatch demo
1 parent fb201e0 commit 9b04f25

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

examples/shapes_and_collections/hatch_demo.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@
66
Hatching (pattern filled polygons) is supported currently in the PS,
77
PDF, SVG and Agg backends only.
88
"""
9+
import numpy as np
910
import matplotlib.pyplot as plt
1011
from matplotlib.patches import Ellipse, Polygon
1112

13+
x = np.arange(1, 5)
14+
y1 = np.arange(1, 5)
15+
y2 = np.ones(y1.shape) * 4
16+
1217
fig, (ax1, ax2, ax3) = plt.subplots(3)
1318

14-
ax1.bar(range(1, 5), range(1, 5), color='red', edgecolor='black', hatch="/")
15-
ax1.bar(range(1, 5), [6] * 4, bottom=range(1, 5),
16-
color='blue', edgecolor='black', hatch='//')
19+
ax1.bar(x, y1, edgecolor='black', hatch="/")
20+
ax1.bar(x, y2, bottom=y1, edgecolor='black', hatch='//')
1721
ax1.set_xticks([1.5, 2.5, 3.5, 4.5])
1822

19-
bars = ax2.bar(range(1, 5), range(1, 5), color='yellow', ecolor='black') + \
20-
ax2.bar(range(1, 5), [6] * 4, bottom=range(1, 5),
21-
color='green', ecolor='black')
23+
ax2.bar(x, y1, edgecolor='black', hatch=['-', '+', 'x', '\\'])
24+
ax2.bar(x, y2, bottom=y1, edgecolor='black', hatch=['*', 'o', 'O', '.'])
2225
ax2.set_xticks([1.5, 2.5, 3.5, 4.5])
2326

24-
patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.')
25-
for bar, pattern in zip(bars, patterns):
26-
bar.set_hatch(pattern)
27-
2827
ax3.fill([1, 3, 3, 1], [1, 1, 2, 2], fill=False, hatch='\\')
2928
ax3.add_patch(Ellipse((4, 1.5), 4, 0.5, fill=False, hatch='*'))
3029
ax3.add_patch(Polygon([[0, 0], [4, 1.1], [6, 2.5], [2, 1.4]], closed=True,

0 commit comments

Comments
 (0)
0