|
1 | 1 | """
|
2 | 2 | =================
|
3 |
| -Stacked Bar Graph |
| 3 | +Stacked bar chart |
4 | 4 | =================
|
5 | 5 |
|
6 | 6 | This is an example of creating a stacked bar plot with error bars
|
|
13 | 13 | import matplotlib.pyplot as plt
|
14 | 14 |
|
15 | 15 |
|
16 |
| -N = 5 |
| 16 | +labels = ['G1', 'G2', 'G3', 'G4', 'G5'] |
17 | 17 | men_means = [20, 35, 30, 35, 27]
|
18 | 18 | women_means = [25, 32, 34, 20, 25]
|
19 | 19 | men_std = [2, 3, 4, 1, 2]
|
20 | 20 | women_std = [3, 5, 2, 3, 3]
|
21 |
| -ind = np.arange(N) # the x locations for the groups |
22 | 21 | width = 0.35 # the width of the bars: can also be len(x) sequence
|
23 | 22 |
|
24 | 23 | fig, ax = plt.subplots()
|
25 | 24 |
|
26 |
| -ax.bar(ind, men_means, width, yerr=men_std, label='Men') |
27 |
| -ax.bar(ind, women_means, width, yerr=women_std, bottom=men_means, |
| 25 | +ax.bar(labels, men_means, width, yerr=men_std, label='Men') |
| 26 | +ax.bar(labels, women_means, width, yerr=women_std, bottom=men_means, |
28 | 27 | label='Women')
|
29 | 28 |
|
30 | 29 | ax.set_ylabel('Scores')
|
31 | 30 | ax.set_title('Scores by group and gender')
|
32 |
| -ax.set_xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5')) |
33 |
| -ax.set_yticks(np.arange(0, 81, 10)) |
34 | 31 | ax.legend()
|
35 | 32 |
|
36 | 33 | plt.show()
|
0 commit comments