|
6 | 6 | Hatching (pattern filled polygons) is supported currently in the PS,
|
7 | 7 | PDF, SVG and Agg backends only.
|
8 | 8 | """
|
| 9 | +import numpy as np |
9 | 10 | import matplotlib.pyplot as plt
|
10 | 11 | from matplotlib.patches import Ellipse, Polygon
|
11 | 12 |
|
| 13 | +x = np.arange(1, 5) |
| 14 | +y1 = np.arange(1, 5) |
| 15 | +y2 = np.ones(y1.shape) * 4 |
| 16 | + |
12 | 17 | fig, (ax1, ax2, ax3) = plt.subplots(3)
|
13 | 18 |
|
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='//') |
17 | 21 | ax1.set_xticks([1.5, 2.5, 3.5, 4.5])
|
18 | 22 |
|
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', '.']) |
22 | 25 | ax2.set_xticks([1.5, 2.5, 3.5, 4.5])
|
23 | 26 |
|
24 |
| -patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.') |
25 |
| -for bar, pattern in zip(bars, patterns): |
26 |
| - bar.set_hatch(pattern) |
27 |
| - |
28 | 27 | ax3.fill([1, 3, 3, 1], [1, 1, 2, 2], fill=False, hatch='\\')
|
29 | 28 | ax3.add_patch(Ellipse((4, 1.5), 4, 0.5, fill=False, hatch='*'))
|
30 | 29 | ax3.add_patch(Polygon([[0, 0], [4, 1.1], [6, 2.5], [2, 1.4]], closed=True,
|
|
0 commit comments