如何在Python直方图中包含对数垃圾箱 [英] How to have logarithmic bins in a Python histogram
本文介绍了如何在Python直方图中包含对数垃圾箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
据我所知,直方图函数中的Log = True选项仅指y轴.
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')
我需要将垃圾箱在log10中等距放置.有什么可以做到的吗?
I need the bins to be equally spaced in log10. Is there something that can do this?
推荐答案
使用logspace()创建几何序列,并将其传递给bins参数.并将xaxis的比例设置为对数比例.
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()
这篇关于如何在Python直方图中包含对数垃圾箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文