Reputation: 790
For example:
import matplotlib.pyplot as plt
data = [0.6, 0.8, 0.4, 0.2, 0.6, 0.8, 0.4, 0.2]
plt.hist(data, bins=20, range=[0.0, 1.0], normed=True)
plt.show()
And after this i taken histogram, where frequency for every item about 5, not 0.25%. How i can fix this?
Upvotes: 0
Views: 1588
Reputation: 8400
You could check the histogram result by assigning plt.hist
as follows:
out = plt.hist(data, bins=20)
print out
which prints:
(array([2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2]),
array([0.2 , 0.23, 0.26, 0.29, 0.32, 0.35, 0.38, 0.41, 0.44, 0.47,
0.5 , 0.53, 0.56, 0.59, 0.62, 0.65, 0.68, 0.71, 0.74, 0.77, 0.8 ]),
<a list of 20 Patch objects>)
which is correct. also:
>>> plt.hist(data, bins=4)
(array([ 2., 2., 2., 2.]), array([ 0.2 , 0.35, 0.5 , 0.65, 0.8 ]),
<a list of 4 Patch objects>)
Upvotes: 1