我正在努力为我在网上找到的 Facebook 数据绘制幂律图。我正在使用 Networkx,并且我已经找到了如何绘制学位直方图和学位等级的方法。我遇到的问题是我希望 y 轴是一个概率,所以我假设我需要总结每个 y 值并除以节点总数?谁能帮我做到这一点?一旦我得到了这个,我想画一个对数对数图,看看我是否能得到一条直线。如果有人可以提供帮助,我将不胜感激!这是我的代码:
import collections
import networkx as nx
import matplotlib.pyplot as plt
from networkx.algorithms import community
import math
import pylab as plt
g = nx.read_edgelist("/Users/Michael/Desktop/anaconda3/facebook_combined.txt","r")
nx.info(g)
degree_sequence = sorted([d for n, d in g.degree()], reverse=True)
degreeCount = collections.Counter(degree_sequence)
deg, cnt = zip(*degreeCount.items())
fig, ax = plt.subplots()
plt.bar(deg, cnt, width=0.80, color='b')
plt.title("Degree Histogram for Facebook Data")
plt.ylabel("Count")
plt.xlabel("Degree")
ax.set_xticks([d + 0.4 for d in deg])
ax.set_xticklabels(deg)
plt.show()
plt.loglog(degree_sequence, 'b-', marker='o')
plt.title("Degree rank plot")
plt.ylabel("Degree")
plt.xlabel("Rank")
plt.show()