python - 简单的肥尾对数分箱

标签 python numpy matplotlib networkx binning

我试图从 Plotting log-binned network degree distributions 中简化日志分级 输出显示原始分布和对数分箱分布。然而,后者并没有像预期的那样单调递减,与原来的偏差很大。 这个问题的最佳解决方案是什么?

import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

m = 3
N = 900

G = nx.barabasi_albert_graph(N, m)

degree_list=nx.degree(G).values()

kmin=min(degree_list)
kmax=max(degree_list)

bins=[float(k-0.5) for k in range(kmin,kmax+2,1)]
density, binedges = np.histogram(degree_list, bins=bins, density=True)
bins = np.delete(bins, -1)

logBins = np.logspace(np.log10(kmin), np.log10(kmax),num=20)
logBinDensity, binedges = np.histogram(degree_list, bins=logBins, density=True)
logBins = np.delete(logBins, -1)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xscale('log')
ax.set_yscale('log')

plt.plot(bins,density,'x',color='black')
plt.plot(logBins,logBinDensity,'x',color='blue')
plt.show()

最佳答案

噪声是由于 N 较小,而小值的偏移是由于 logbin 宽度小于 1。添加

for x in range(len(logBins)):
    logBins[x] = mt.ceil(logBins[x])

关于python - 简单的肥尾对数分箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21921185/

相关文章:

Python:连接 scipy 稀疏矩阵

python - 仅在一个窗口中显示更新图像

python - numpy 在一行中找到最大值并返回到它的列索引

python - Numpy 数组 - 使用 reshape 将多列堆叠为一列

python - 写入和读取 ndarray

python - 感知上更统一的颜色图?

python - 如何强制 python 在饼图中显示整个标签

Python TypeError : must be str, 不是 int

Python——将字符串转换为列表

matplotlib - 如何在浏览器(html)中显示matplotlib图表?