Setting a relative frequency in a matplotlib histogram

后端 未结 2 510
攒了一身酷
攒了一身酷 2020-12-13 13:46

I have data as a list of floats and I want to plot it as a histogram. Hist() function does the job perfectly for plotting the absolute histogram. However, I cannot figure ou

2条回答
  •  难免孤独
    2020-12-13 14:23

    Because normed option of hist returns the density of points, e.g dN/dx

    What you need is something like that:

     # assuming that mydata is an numpy array
     ax.hist(mydata, weights=np.zeros_like(mydata) + 1. / mydata.size)
     # this will give you fractions
    

提交回复
热议问题