据我所知,直方图函数中的选项Log=True仅指y轴。
P.hist(d,bins=50,log=True,alpha=0.5,color='b',histtype='step')
我需要在log10中等间距放置垃圾箱。有没有什么东西可以做到这一点?
发布于 2011-07-28 16:37:06
使用logspace()创建几何序列,并将其传递给bins参数。并将X轴的刻度设置为对数刻度。
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()
发布于 2014-08-04 08:52:11
最直接的方法是只计算限制的log10,计算线性间隔的bin,然后通过升幂10将其转换回来,如下所示:
import pylab as pl
import numpy as np
data = np.random.normal(size=10000)
MIN, MAX = .01, 10.0
pl.figure()
pl.hist(data, bins = 10 ** np.linspace(np.log10(MIN), np.log10(MAX), 50))
pl.gca().set_xscale("log")
pl.show()
发布于 2018-04-21 19:45:27
下面的代码说明了如何将bins='auto'
与对数刻度一起使用。
import numpy as np
import matplotlib.pyplot as plt
data = 10**np.random.normal(size=500)
_, bins = np.histogram(np.log10(data + 1), bins='auto')
plt.hist(data, bins=10**bins);
plt.gca().set_xscale("log")
https://stackoverflow.com/questions/6855710
复制相似问题