stacked bar chart

Solutions on MaxInterview for stacked bar chart by the best coders in the world

showing results for - "stacked bar chart"
Rodrigo
28 Oct 2020
1import matplotlib.pyplot as plt
2
3
4labels = ['G1', 'G2', 'G3', 'G4', 'G5']
5men_means = [20, 35, 30, 35, 27]
6women_means = [25, 32, 34, 20, 25]
7men_std = [2, 3, 4, 1, 2]
8women_std = [3, 5, 2, 3, 3]
9width = 0.35       # the width of the bars: can also be len(x) sequence
10
11fig, ax = plt.subplots()
12
13ax.bar(labels, men_means, width, yerr=men_std, label='Men')
14ax.bar(labels, women_means, width, yerr=women_std, bottom=men_means,
15       label='Women')
16
17ax.set_ylabel('Scores')
18ax.set_title('Scores by group and gender')
19ax.legend()
20
21plt.show()
22