I really can't get into hist() barstacked

Sandro Tosi ha scritto:

Sandro Tosi ha scritto:

Hi all,
I'd like to do a histogram with barstacked style. Well, I'm not able
to make it in any way :frowning:

- what is the format of the the data to pass?
- what's the value of bins? (related to the above question, I suppose)

for example, let's say I want to plot this series

s1 = 2,3,6,3,1
s2 = 1,2,2,4,1
s3 = 4,1,0,3,7

what's the format of data to pass to hist() ? by row? by column?

Thanks a lot in advance,

I think hist() *computes* histograms ; you can find information here:

http://matplotlib.sourceforge.net/api/pyplot_api.html

and infact I want a barstacked histogram

So you want to
1) compute your histogram from your series of values and then
2) display the several histograms as a stacked bar graph

or just
1) display already-calculated histogram values as a stacked bar graph

These are two different things. Since it seems you want to pass directly
s1,s2,s3, it seems that they are your already calculated histogram
values. In this case hist() is of no utility for you.

It seems from your example that you already have the histogram computed

no, I just have a series of lists to plot, I didn't compute anything.

Ok, so you want a bar graph and not to compute a histogram.

and that you want to plot the bar graph; in this case you should look to
bar()

In the page linked above you find also the example on how to do a
barstacked graph.

sure, for 2 data sets might be fine: but what for 10 ? how to use the
bottom argument in that case?

Ehm, it seems pretty straighforward to me.
I attach the same example of the webpage but extended with three bar
graphs stacked. I admit that the fact the example used tuples for the
values made it unnecessarily awkward; using numpy arrays everything goes
to place:

#!/usr/bin/env python
# a stacked bar plot with errorbars
import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = np.array([20, 35, 30, 35, 27])
womenMeans = np.array([25, 32, 34, 20, 25])
xMeans = np.array([17, 11, 43, 5, 18])
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, color='r', yerr=womenStd)
p2 = plt.bar(ind, womenMeans, width, color='y',
             bottom=menMeans, yerr=menStd)
p3 = plt.bar(ind, xMeans, width, color='b', bottom=womenMeans+menMeans)

plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') )
plt.yticks(np.arange(0,81,10))
plt.legend( (p1[0], p2[0], p3[0]), ('Men', 'Women','Aliens') )

plt.show()

···

On Wed, Jul 22, 2009 at 10:25, ms<devicerandom@...287...> wrote: