3

I know how to create an histogram in Python, but I would like that it is the probability density distribution.

Let's start with my example. I have an array d, with a size of 500000 elements. With the following code I am building a simple histogram telling me how many elements of my array d are between every bin.

max_val=log10(max(d))
min_val=log10(min(d))

logspace = np.logspace(min_val, max_val, 50)
H=hist(select,bins=logspace,histtype='step')

The problem is that this plot is not what I want. I would like to have the probability distribution function of my array d. Instead of having the number of elements of my array which are within every bins, I would like to have the probability of them being in that bin. I tried with normed=True, but that seems not working since I have bins which are equally logspaced.

2
  • By 50.0000 did you mean 50000? 500000? Commented Aug 15, 2011 at 8:33
  • 2
    You are probably using hist from matplotlib, not histogram from numpy. Commented Aug 15, 2011 at 8:43

1 Answer 1

2

It's not clear what your hist function is. If you're using NumPy's histogram, try setting density=True. See http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html .

Sign up to request clarification or add additional context in comments.

3 Comments

Matteo is probably using hist from matplotlib, not histogram from numpy.
Yes, I am using hist from matplotlib. I tried with histogram from numpy with density=True but I got this error: TypeError: histogram() got an unexpected keyword argument 'density'
I got that error as well but it was fixed by updating to numpy 1.6.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.