【问题标题】:Plot cumulative distribution with networkx and numpy使用 networkx 和 numpy 绘制累积分布
【发布时间】:2020-12-03 00:28:01
【问题描述】:

我想实现图表的累积分布。这是我的代码:

g = nx.read_edgelist('graph', create_using= nx.Graph(), nodetype=int)
degree_sequence = sorted([d for n, d in g.degree()], reverse=True)  # degree sequence
degreeCount = collections.Counter(degree_sequence)
deg, cnt = zip(*degreeCount.items())
cs = np.cumsum(deg)
plt.loglog(deg, cs, 'bo')
plt.title("Cumulative Distribution plot")
plt.ylabel("Sample with value > Degree")
plt.xlabel("Degree")
plt.show()

要绘制累积图,我知道我必须在 x 轴上有度数,在 y 轴上必须有值 > 度数的样本。使用我的代码的结果如下:

但预期的结果必须是这样的:

我不确定我是否使用我的代码获得了预期的情节。如果有问题,谁能帮我解释一下?

【问题讨论】:

    标签: python numpy networkx distribution


    【解决方案1】:

    我认为应该是:

    cs = np.cumsum(cnt)
    

    完整代码:

    g = nx.read_edgelist('graph', create_using= nx.Graph(), nodetype=int)
    degree_sequence = sorted([d for n, d in g.degree()], reverse=True)  # degree sequence
    degreeCount = collections.Counter(degree_sequence)
    deg, cnt = zip(*degreeCount.items())
    cs = np.cumsum(cnt)
    plt.loglog(deg, cs, 'bo')
    plt.title("Cumulative Distribution plot")
    plt.ylabel("Sample with value > Degree")
    plt.xlabel("Degree")
    plt.show()
    

    通常在实现累积度数分布时,您希望获得给定度数之前的总计数,P(K

    【讨论】:

      猜你喜欢
      • 2015-04-27
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 2012-05-25
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      相关资源
      最近更新 更多