试试看它的大小。
注意:我添加了一个现有边的副本,目的只是为了显示当多图中有重复时的行为。
from collections import Counterc = Counter(g.edges()) # Contains frequencies of each directed edge.for u, v, d in g.edges(data=True): d['weight'] = c[u, v]print(list(g.edges(data=True)))#[(340, 269, {'weight': 1}),# (340, 340, {'weight': 1}),# (269, 340, {'weight': 1}),# (398, 279, {'weight': 1}),# (69, 28, {'weight': 1}),# (382, 27, {'weight': 1}),# (27, 285, {'weight': 2}),# (27, 285, {'weight': 2}),# (120, 422, {'weight': 1}),# (422, 217, {'weight': 1}),# (217, 340, {'weight': 1}),# (458, 442, {'weight': 1}),# (291, 431, {'weight': 1}),# (68, 27, {'weight': 1}),# (112, 269, {'weight': 1})]
编辑: 要以边缘权重为厚度可视化图形,请使用以下命令:
nx.draw_networkx(g, width=[d['weight'] for _, _, d in g.edges(data=True)])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)