Skip to content

Commit 94c47e2

Browse files
author
Matthias Bussonnier
committed
Update bar stacked example to directly manipulate axes.
Avoid using the stateful plt interface
1 parent 64ba969 commit 94c47e2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/lines_bars_and_markers/bar_stacked.py

Lines changed: 9 additions & 7 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,
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,
2628
label='Women')
2729

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()
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)