How to normalize a histogram in python?

前端 未结 5 1170
星月不相逢
星月不相逢 2021-02-12 11:35

I\'m trying to plot normed histogram, but instead of getting 1 as maximum value on y axis, I\'m getting different numbers.

For array k=(1,4,3,1)

 import         


        
5条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 11:56

    One way is to get the probabilities on your own, and then plot with plt.bar:

    In [91]: from collections import Counter
        ...: c=Counter(k)
        ...: print c
    Counter({1: 2, 3: 1, 4: 1})
    
    In [92]: plt.bar(prob.keys(), prob.values())
        ...: plt.show()
    

    result: enter image description here

提交回复
热议问题