我正在使用Python中的NetworkX进行网络分析。我需要为每条边确定权重并按以下方式将其添加到图形中:
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
airports = ['ATL','LAX','ORD']
weights = [500,200,150] #Note that in my real code I I calculated these weights, they are not provided
G = nx.Graph()
G.add_nodes_from(airports)
weightlst = []
airports_pos = []
checked_airports = []
i = 0
for airport1 in airports:
for airport2 in airports:
if airport1 != airport2 and checked_airports.count([airport1,airport2])==0 and checked_airports.count([airport2,airport1])==0:
weightedge = weights[i]
weightlst.append(weightedge)
weightedge = weightedge*0.0020+0.5
G.add_edge(airport1, airport2, weight=weightedge)
checked_airports.append([airport1,airport2])
i = i + 1
为了更好的理解,每条边所代表的权重表示两个机场之间有多少次航班往返。我的问题在于,由于无关紧要的边线被画在相关的线上面,使得我们难以看出哪些“航线”最繁忙。我希望将权重最高的边线最后绘制,这样就清晰明了地显示出网络中哪些是“最繁忙的航班路线”。