具有可变权重的边无法正确连接节点

问题描述

我正在使用 NetworkX 绘制具有可变权重的边的节点网络。权重为 1 的边与节点完全连接,但权重大于 1 的边未到达节点。任何帮助将不胜感激。这是我使用的代码

`from matplotlib import pyplot as plt
import networkx as nx
import numpy as np

#step1: construct the network based on adjacency network
A1 = np.array([[0,1,1],[5,2,0],[1,0]])
G1 = nx.DiGraph(A1)

#step2: add the node attribute
nNodes = G1.number_of_nodes()
column = [str(i+1) for i in range(nNodes)] #1,3,4
mapping = {0:'1'}
for i in range(0,len(column)-1):
    mapping.setdefault(i+1,column[i+1])
G1 = nx.relabel_nodes(G1,mapping)

#step3: add the node and edge color
node_siz = [100 for node in G1.nodes()]
node_col = ['orange' for node in G1.nodes()]
#edge_width = [1 for edge in G1.edges()]
edge_width = list()
for i in range(len(list(G1.edges))):
    start = int(list(G1.edges)[i][0])- 1
    end = int(list(G1.edges)[i][1])- 1
    edge_width.append(A1[start][end])
edge_col = ['grey' for edge in G1.edges()]

#step4: add the position of nodes
pos = {}
x_list = [0,1]
y_list = [0,1]
for i in range(len(G1.nodes)):
    pos[mapping[i]] = np.array([x_list[i],y_list[i]])
fig = plt.figure(figsize = (3,2),dpi = 1200) 

nx.draw(G1,with_labels = True,pos=pos,node_size =node_siz,node_color = node_col,edge_color 
= edge_col,width = edge_width,linewidths = 1,edgecolors='black',) 
fig.savefig('samplenetwork.png',format='png',dpi=1200,bBox_inches = 'tight')`

结果:

Result

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)