How to normalize a histogram in python?

前端 未结 5 1159
星月不相逢
星月不相逢 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:53

    How the lines above:

    weights = np.ones_like(myarray)/float(len(myarray))
    plt.hist(myarray, weights=weights)
    

    should work when I have a stacked histogram like this?-

    n, bins, patches = plt.hist([from6to10, from10to14, from14to18, from18to22,  from22to6],
    label= ['06:00-10:00','10:00-14:00','14:00-18:00','18:00- 22:00','22:00-06:00'],
    stacked=True,edgecolor='black', alpha=0.8, linewidth=0.5, range=(np.nanmin(ref1arr),
    stacked=True,edgecolor='black', alpha=0.8, linewidth=0.5, range=(np.nanmin(ref1arr), np.nanmax(ref1arr)), bins=10)
    

提交回复
热议问题