pylab.hist(data, normed=1). Normalization seems to work incorrect

后端 未结 7 1265
感情败类
感情败类 2020-12-01 07:40

I\'m trying to create a histogram with argument normed=1

For instance:

import pylab

data = ([1,1,2,3,3,3,3,3,4,5.1])    
pylab.hist(data, normed=1)
         


        
相关标签:
7条回答
  • 2020-12-01 08:14

    What this normalization did?

    In order to normalize a sequence, you have to take into account the bin size. According to the documentation , the default number of bin is 10. Consequently, the bin size is (data.max() - data.min() )/10, that is 0.41. If normed=1, then the heights of the bar is such that the sum, multiplied by 0.41, gives 1. This is what happens when you integrate.

    And how to create a histogram with such normalization that the integral of the histogram would be equal 1?

    I think that you want the sum of the histogram, not its integral, to be equal to 1. In this case the quickest way seems:

    h = plt.hist(data)
    norm = sum(data)
    h2 = [i/norm for i in h[0]]
    plt.bar(h[1],h2)
    
    0 讨论(0)
提交回复
热议问题