plotting normalized histograms

hi all,

i have a matrix of data and i would like to make a set of subplots,
each subplot with a histgram of one of the columns of the data. the
dataset is an Nx4 matrix containing only numbers between 0 and 1.

i plot it like this:

plt.subplot(2, 2, 1)
# histogram of first column
plt.hist(mydata[:, 0], 15)
plt.subplot(2, 2, 1)
# histogram of second column
plt.hist(mydata[:, 1], 15)
# etc...

since i want the subplots to be comparable, i'd like hist to use the
same bins for all subplots. how can i do this?

also, i would like to, instead of showing counts on the y-axis, show
the normalized probability of each bin. i looked into the "normed"
optional argument, but i don't think it achieves this. my attempt to
do this was:

plt.hist(mydata[:, 0], 15, normed=1)

but the y-axis is not set to be between 0 and 1.

any ideas on how to do this would be greatly appreciated. thanks.

plt.hist(mydata[:, 0]

In a PDF area underneath the given curve (histogram in your case) should be equal to 1. Setting normed to True satisfies this condition.

One thing that always confuses me is how to label y-axis in this case? Apparently, one cannot say “probability” because they are not exactly probabilities due to the definition of PDF. “Probability density” maybe a good candidate looking at the example on the web.

Any ideas about this?

···

On Fri, Oct 16, 2009 at 7:04 PM, per freem <perfreem@…83…287…> wrote:

hi all,

i have a matrix of data and i would like to make a set of subplots,

each subplot with a histgram of one of the columns of the data. the

dataset is an Nx4 matrix containing only numbers between 0 and 1.

i plot it like this:

plt.subplot(2, 2, 1)

histogram of first column

plt.hist(mydata[:, 0], 15)

plt.subplot(2, 2, 1)

histogram of second column

plt.hist(mydata[:, 1], 15)

etc…

since i want the subplots to be comparable, i’d like hist to use the

same bins for all subplots. how can i do this?

also, i would like to, instead of showing counts on the y-axis, show

the normalized probability of each bin. i looked into the “normed”

optional argument, but i don’t think it achieves this. my attempt to

do this was:

plt.hist(mydata[:, 0], 15, normed=1)

but the y-axis is not set to be between 0 and 1.

any ideas on how to do this would be greatly appreciated. thanks.

plt.hist(mydata[:, 0]


Come build with us! The BlackBerry(R) Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and stay

ahead of the curve. Join us from November 9 - 12, 2009. Register now!

http://p.sf.net/sfu/devconference


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan

it would be nice to be able to plot histograms with bins labeled directly in
percents, but it isn't supported by hist(). Workaround is to change either
your data or your axis.

http://sourceforge.net/tracker/?func=detail&aid=2775888&group_id=80706&atid=560723
Tracker: Feature Requests
5 hist plot in percent - ID: 2775888
Last Update: Tracker Item Submitted ( nobody )
Details:

except for normed=1 there is no way to control the y output of hist.
being able to specify an output in percent would be useful.

hist(x, percent=1)
plots y/n*100 histograms
Submitted:

Nobody/Anonymous ( nobody ) - 2009-04-20 08:48

···

--
View this message in context: http://www.nabble.com/plotting-normalized-histograms-tp25934001p25944567.html
Sent from the matplotlib - users mailing list archive at Nabble.com.