python plot 和 powerlaw 适合

标签 python matplotlib power-law

我有以下列表:

[6, 4, 0, 0, 0, 0, 0, 1, 3, 1, 0, 3, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 3, 3, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 3, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 2, 2, 3, 2, 1, 0, 0, 0, 1, 2]

我想用 python 绘制每个实体的频率并对其进行幂律分析。

但我不知道如何使用 ylabel 频率和 xlabel 列表中的数字来绘制列表。

我想用频率创建一个字典并绘制字典的值,但那样的话,我无法将数字放在 xlabel 上。

有什么建议吗?

最佳答案

使用包:powerlaw

import powerlaw
d=[6, 4, 0, 0, 0, 0, 0, 1, 3, 1, 0, 3, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3,2,  3, 3, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 1,0, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1,3, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 2, 2, 3, 2, 1, 0, 0, 0, 1, 2]
fit = powerlaw.Fit(numpy.array(d)+1,xmin=1,discrete=True)
fit.power_law.plot_pdf( color= 'b',linestyle='--',label='fit ccdf')
fit.plot_pdf( color= 'b')

print('alpha= ',fit.power_law.alpha,'  sigma= ',fit.power_law.sigma)

α= 1.85885487521 西格玛= 0.0858854875209

enter image description here

它允许正确地绘制、拟合和分析数据。它具有特殊的拟合离散数据幂律分布的方法。

它可以安装:pip install powerlaw

关于python plot 和 powerlaw 适合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16640496/

相关文章:

python - 如何从 Unicode 文件中删除字母数字单词

Python Matplotlib slider 小部件未更新

python - 获取轮廓最高点的坐标

python - Django 图片上传不上传日语命名图片

python - 更新的数据框 - 保留最后的更新 - 数据框 pandas

python - Matplotlib:如何在绘图左侧添加 1 英寸间隙?

r - 使用 powerlaw 包绘制多个幂律图

python - 使用 PyMC 拟合幂律函数

python - 同时平铺和修改 Numpy 数组