How to have logarithmic bins in a Python histogram

前端 未结 4 1218
天涯浪人
天涯浪人 2020-12-07 12:25

As far as I know the option Log=True in the histogram function only refers to the y-axis.

P.hist(d,bins=50,log=True,alpha=0.5,color=\'b\',histtype=\'step\')
         


        
4条回答
  •  既然无缘
    2020-12-07 12:33

    use logspace() to create a geometric sequence, and pass it to bins parameter. And set the scale of xaxis to log scale.

    import pylab as pl
    import numpy as np
    
    data = np.random.normal(size=10000)
    pl.hist(data, bins=np.logspace(np.log10(0.1),np.log10(1.0), 50))
    pl.gca().set_xscale("log")
    pl.show()
    

    enter image description here

提交回复
热议问题