python中的图度分布

2024-05-06 14:25:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我试图为一些数据绘制度分布图。因此,我编写了以下函数:

def plotDegDistLogLog(G):
    degree_sequence = sorted([d for n, d in G.degree()], reverse=True)  # degree sequence
    degreeCount = collections.Counter(degree_sequence)
    deg, cnt = zip(*degreeCount.items())
    frac = [n/G.number_of_nodes() for n in cnt]
    fig, ax = plt.subplots()
    plt.plot(deg, frac, 'o')
    ax.set_yscale('log')
    ax.set_xscale('log')
    plt.ylabel("Fraction of nodes")
    plt.xlabel("Degree")
    plt.show()

我想问:

  • 如何创建大小呈指数增长的垃圾箱
  • 在每个箱子中,我如何将计数之和除以箱子长度

我想画一条线


Tags: ofinlogforpltaxnodessequence
1条回答
网友
1楼 · 发布于 2024-05-06 14:25:27

使用hist, bins = numpy.histogram(x, bins, density=True)可以显式指定bins,因此可以选择所需内容(例如bins = numpy.exp(numpy.arange(10)))。density参数允许对直方图进行规格化。或者您可以将hist的每个点除以bins[:-1]中的每个bin

相关问题 更多 >