Skip to content

Update bar stacked example to directly manipulate axes. #14868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions examples/lines_bars_and_markers/bar_stacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence

plt.bar(ind, men_means, width, yerr=men_std, label='Men')
plt.bar(ind, women_means, width, yerr=women_std, bottom=men_means,
label='Women')

plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
plt.yticks(np.arange(0, 81, 10))
plt.legend()
fig, ax = plt.subplots()

ax.bar(ind, men_means, width, yerr=men_std, label='Men')
ax.bar(ind, women_means, width, yerr=women_std, bottom=men_means,
label='Women')

ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
ax.set_yticks(np.arange(0, 81, 10))
ax.legend()

plt.show()