gpt4 book ai didi

python - python 中的缩放对数合并

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:39 30 4
gpt4 key购买 nike

我对绘制一组按幂律分布的点的概率分布很感兴趣。此外,我想使用对数合并来消除尾部的大波动。如果我只是使用对数分箱,并将其绘制在对数对数刻度上,例如

pl.hist(MyList,log=True, bins=pl.logspace(0,3,50))
pl.xscale('log')

例如,那么问题是更大的箱子占更多的点,即我的箱子的高度没有按箱子大小缩放。

有没有一种方法可以使用对数分箱,同时让 python 按分箱的大小缩放所有高度?我知道我可能可以手动以某种迂回方式执行此操作,但似乎这应该是一个存在的功能,但我似乎找不到它。如果您认为直方图从根本上说是一种糟糕的表示数据的方法,并且您有更好的想法,那么我也很乐意听到。

谢谢!

最佳答案

如果您对直方图有特殊要求,Matplotlib 将无济于事。但是,您可以使用 numpy 轻松创建和操作直方图。

import numpy as np
from matplotlib import pyplot as plt

# something random to plot
data = (np.random.random(10000)*10)**3

# log-scaled bins
bins = np.logspace(0, 3, 50)
widths = (bins[1:] - bins[:-1])

# Calculate histogram
hist = np.histogram(data, bins=bins)
# normalize by bin width
hist_norm = hist[0]/widths

# plot it!
plt.bar(bins[:-1], hist_norm, widths)
plt.xscale('log')
plt.yscale('log')

显然,当您以这种不明显的方式呈现数据时,您必须非常小心如何正确标记您的 y 轴并编写信息丰富的图形标题。

关于python - python 中的缩放对数合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37170511/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com