How to have logarithmic bins in a Python histogram

前端 未结 4 1212
天涯浪人
天涯浪人 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:31

    In addition to what was stated, performing this on pandas dataframes works as well:

    some_column_hist = dataframe['some_column'].plot(bins=np.logspace(-2, np.log10(max_value), 100), kind='hist', loglog=True, xlim=(0,max_value))
    

    I would caution, that there may be an issue with normalizing the bins. Each bin is larger than the previous one, and therefore must be divided by it's size to normalize the frequencies before plotting, and it seems that neither my solution, nor HYRY's solution accounts for this.

    Source: https://arxiv.org/pdf/cond-mat/0412004.pdf

提交回复
热议问题