I have a question regarding the hist() function with matplotlib.
I am writing a code to plot a histogram of data who's value varies from 0 to 1. For example:
values = [0.21, 0.51, 0.41, 0.21, 0.81, 0.99]
bins = np.arange(0, 1.1, 0.1)
a, b, c = plt.hist(values, bins=bins, normed=0)
plt.show()
The code above generates a correct histogram (I could not post an image since I do not have enough reputation). In terms of frequencies, it looks like:
[0 0 2 0 1 1 0 0 1 1]
I would like to convert this output to a discrete probability mass function, i.e. for the above example, I would like to get a following frequency values:
[ 0. 0. 0.333333333 0. 0.166666667 0.166666667 0. 0. 0.166666667 0.166666667 ] # each item in the previous array divided by 6)
I thought I simply need to change the parameter in the hist() function to 'normed=1'. However, I get the following histogram frequencies:
[ 0. 0. 3.33333333 0. 1.66666667 1.66666667 0. 0. 1.66666667 1.66666667 ]
This is not what I expect and I don't know how to get the discrete probability mass function who's sum should be 1.0. A similar question was asked in the following link (link to the question), but I do not think the question was resolved.
I appreciate for your help in advance.