I really can't get into hist() barstacked

Sandro Tosi ha scritto:

I got only data values, nothing already "computed" (for whatever you
mean by that), and I want to plot stacked bars with those values
(either by row or by column).

Ok, I see.

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.

what is the difference? maybe I didn't get it right :wink:

Oh, sorry, I thought it was common knowledge. That's why I didn't
understand at beginning :slight_smile:

A histogram is a *statistical technique* which takes a vector of data,
classifies them into bins (usually magnitude intervals), counts the
number of data points into each bin and returns another vector with the
number of data points for each bin.

It is a technique to get an approximation of the distribution underlying
your data; it is not the only one (for example I am a big fan of kernel
density estimation, which is, roughly speaking, the continuous extension
of the histogram)

A bar graph is a representation of data as bars of different heights.
Usually people display histograms with bar graphs, each bar being a bin,
and for this reason they often confuse the two things :slight_smile:

But they're two different and quite unrelated things: there's nothing
intrinsically wrong in plotting histograms as line or scatter plots, for
example, and you can do bar graphs of things which are not histograms.

So it seems you want a bar graph :),and that's why hist() is of little
help for you.

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.


p3 = plt.bar(ind, xMeans, width, color='b', bottom=womenMeans+menMeans)

do you really expect it to be straightforward for 10, 100 or for any
other dynamically generated data? let's imagine today I get 15 sets of
data, tomorrow 20, the next day 7. I cannot do that by hand, and I
want some general way to get stacked by dynamically adaptable to more
columns with more "blocks" in them.

I didn't try, but isn't it easily done with a for cycle? Instead of
having p1,p2,p3 you have a vector pN=[...] where you append the bars,
and the bottom is the sum of the previous values of your bars.

Not counting the fact that if you have 100 data sets, maybe a stacked
bar graph begins to be confusing :wink: but hey, that's your choice! :smiley: