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 in Python by Kashish
96 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 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
98 views
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
1,178 views
0 votes
1 answer

What is the recommended way to randomize a list of strings using Python?

Hi. Nice question. Here is the simplified answer ...READ MORE

answered Jan 18 in Python by Nymeria
• 3,520 points
59 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 416 views
+4 votes
6 answers
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 in Python by Vaishnavi
223 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 in Python by Bobin
1,052 views