def Degree_distribution(G):
Nodes = G.nodes()
Degree_List = []
Degree_Dic = {}
for i in Nodes:
Degree_List.append(G.degree(i))
Degree_List = sorted(Degree_List, reverse = False)
Flag = Degree_List[0]
Count = 1
for i in Degree_List[1:]:
if i !=Flag:
Degree_Dic[Flag] = Count
Count = 1
Flag = i
else:
Count = Count + 1
#end for
#print Degree_Dic
n = G.number_of_nodes()
plt.figure(1)
ax1 = plt.subplot(111)
plt.sca(ax1)
#x = list([(i+1) for i in range(0,len(Degree_List))])
x = sorted(Degree_Dic.keys(), reverse = False)
y = []
for i in x:
y.append(float(Degree_Dic[i])/n)
#end for
plt.plot(x, y, "rs-")
plt.ylabel("Probability")
plt.xlabel("Degree K")
plt.title("Degree distribution of networks")
plt.show()
#************************************************************************
评论列表
文章目录