python绘制图的度分布柱状图, draw graph degree histogram with Python
图的度数分布 import collections import matplotlib.pyplot as plt import networkx as nx G = nx.gnp_random_graph(100, 0.02) degree_sequence = sorted([d for n, d in G.degree()], reverse=True) # degree sequence # print "Degree sequence", degree_sequence degreeCount = collections.Counter(degree_sequence) deg, cnt = zip(*degreeCount.items()) # #as an alternation, you can pick out the top N items for the plot: #d = sorted(degreeCount.items(), key=lambda item:item[1], reverse=True)[:30] # pick out the up 30 items from counter #deg = [i[0] for i in d] #cnt = [i[1] for i in d] fig, ax = plt.
…