example of creating a stacked bar plot with error bars using the bar function

0 votes

Can you give an example of creating a stacked bar plot with error bars using the bar function? Thank you

May 27, 2019 in Python by Kashish
1,685 views

1 answer to this question.

0 votes

Have a look at this:

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)
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.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.show()
answered May 27, 2019 by Kunal
why pl[0],p2[0] instead of p1,p2?
p1[0] and p2[0] are used to index the items inside p1 and p2. But honestly, I tried them without specifying indexes. It gives me the same output.

Related Questions In Python

+2 votes
1 answer

How can I record the X,Y limits of a displayed X,Y plot using the matplotlib show() module?

A couple hours after posting this question ...READ MORE

answered Dec 27, 2018 in Python by anonymous
1,143 views
0 votes
1 answer
0 votes
1 answer

Need help writing a dataframe into a csv with the help of a loop

Using the following logic you can arrive ...READ MORE

answered Apr 17, 2018 in Python by anonymous
3,379 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,071 views
0 votes
1 answer

Example of creating horizontal bar chart using matplotlib

Try this: import matplotlib.pyplot as plt import numpy as ...READ MORE

answered May 27, 2019 in Python by Vaishnavi
1,856 views
0 votes
1 answer

Example showing a way to create a grouped bar chart with Matplotlib?

Have a look at this: import matplotlib import matplotlib.pyplot ...READ MORE

answered May 27, 2019 in Python by Bobin
3,244 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP