8000 Cleanup bar_stacked, bar_unit_demo examples. by anntzer · Pull Request #14089 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Cleanup bar_stacked, bar_unit_demo examples. #14089

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
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
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
17 changes: 8 additions & 9 deletions examples/lines_bars_and_markers/bar_stacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@
using `~matplotlib.pyplot.bar`. Note the parameters *yerr* used for
error bars, and *bottom* to stack the women's bars on top of the men's
bars.

"""

import numpy as np
import matplotlib.pyplot as plt


N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
men_means = [20, 35, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
men_std = [2, 3, 4, 1, 2]
women_std = [3, 5, 2, 3, 3]
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence

p1 = plt.bar(ind, menMeans, width, yerr=menStd)
p2 = plt.bar(ind, womenMeans, width,
bottom=menMeans, yerr=womenStd)
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((p1[0], p2[0]), ('Men', 'Women'))
plt.legend()

plt.show()
16 changes: 8 additions & 8 deletions examples/units/bar_unit_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@


N = 5
menMeans = (150*cm, 160*cm, 146*cm, 172*cm, 155*cm)
menStd = (20*cm, 30*cm, 32*cm, 10*cm, 20*cm)
men_means = [150*cm, 160*cm, 146*cm, 172*cm, 155*cm]
men_std = [20*cm, 30*cm, 32*cm, 10*cm, 20*cm]

fig, ax = plt.subplots()

ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
p1 = ax.bar(ind, menMeans, width, bottom=0*cm, yerr=menStd)
ax.bar(ind, men_means, width, bottom=0*cm, yerr=men_std, label='Men')


womenMeans = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm)
womenStd = (30*cm, 25*cm, 20*cm, 31*cm, 22*cm)
p2 = ax.bar(ind + width, womenMeans, width, bottom=0*cm, yerr=womenStd)
women_means = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm)
women_std = (30*cm, 25*cm, 20*cm, 31*cm, 22*cm)
ax.bar(ind + width, women_means, width, bottom=0*cm, yerr=women_std,
label='Women')

ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width / 2)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))

ax.legend((p1[0], p2[0]), ('Men', 'Women'))
ax.legend()
ax.yaxis.set_units(inch)
ax.autoscale_view()

Expand Down
0