-
Notifications
You must be signed in to change notification settings - Fork 922
Expand file tree
/
Copy pathtip-hatched.py
More file actions
40 lines (31 loc) · 1.18 KB
/
tip-hatched.py
File metadata and controls
40 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
import matplotlib.pyplot as plt
cmap = plt.get_cmap("Oranges")
color1, color2 = cmap(0.3), cmap(0.5)
plt.rcParams['hatch.color'] = color1
plt.rcParams['hatch.linewidth'] = 8
fig = plt.figure(figsize=(2, 2))
ax = plt.subplot()
np.random.seed(123)
x1, y1 = 3*np.arange(2), np.random.randint(25, 50, 2)
x2, y2 = x1+1, np.random.randint(25, 75, 2)
ax.bar(x1, y1, color=color2)
for i in range(len(x1)):
plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0, 1),
fontsize="x-small", color=color2,
textcoords="offset points", va="bottom", ha="center")
ax.bar(x2, y2, color=color2, hatch="/" )
for i in range(len(x2)):
plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0, 1),
fontsize="x-small", color=color2,
textcoords="offset points", va="bottom", ha="center")
ax.set_yticks([])
ax.set_xticks(0.5+np.arange(0, 6, 3))
ax.set_xticklabels(["2018", "2019"])
ax.tick_params('x', length=0, labelsize="small", which='major')
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
plt.tight_layout()
plt.savefig("../figures/tip-hatched.pdf")
# plt.show()