Skip to content

Commit a9d1052

Browse files
authored
Merge pull request matplotlib#15121 from timhoffm/fix-bar-stacked-example
Fix Stacked bar graph example
2 parents acfe724 + a8cf29a commit a9d1052

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
=================
3-
Stacked Bar Graph
3+
Stacked bar chart
44
=================
55
66
This is an example of creating a stacked bar plot with error bars
@@ -13,24 +13,21 @@
1313
import matplotlib.pyplot as plt
1414

1515

16-
N = 5
16+
labels = ['G1', 'G2', 'G3', 'G4', 'G5']
1717
men_means = [20, 35, 30, 35, 27]
1818
women_means = [25, 32, 34, 20, 25]
1919
men_std = [2, 3, 4, 1, 2]
2020
women_std = [3, 5, 2, 3, 3]
21-
ind = np.arange(N) # the x locations for the groups
2221
width = 0.35 # the width of the bars: can also be len(x) sequence
2322

2423
fig, ax = plt.subplots()
2524

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,
2827
label='Women')
2928

3029
ax.set_ylabel('Scores')
3130
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))
3431
ax.legend()
3532

3633
plt.show()

0 commit comments

Comments
 (0)