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