Skip to content

Commit f0b110e

Browse files
authored
Merge pull request #14868 from Carreau/manipulate-axes-directly-on-stacked-bar-example
Update bar stacked example to directly manipulate axes.
2 parents 4a5c939 + 2e77a3b commit f0b110e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

examples/lines_bars_and_markers/bar_stacked.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
ind = np.arange(N) # the x locations for the groups
2222
width = 0.35 # the width of the bars: can also be len(x) sequence
2323

24-
plt.bar(ind, men_means, width, yerr=men_std, label='Men')
25-
plt.bar(ind, women_means, width, yerr=women_std, bottom=men_means,
26-
label='Women')
27-
28-
plt.ylabel('Scores')
29-
plt.title('Scores by group and gender')
30-
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
31-
plt.yticks(np.arange(0, 81, 10))
32-
plt.legend()
24+
fig, ax = plt.subplots()
25+
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,
28+
label='Women')
29+
30+
ax.set_ylabel('Scores')
31+
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+
ax.legend()
3335

3436
plt.show()

0 commit comments

Comments
 (0)