Networkx节点大小 [英] Networkx node sizes
问题描述
我正在创建一个networkX图,其节点大小与节点相关.创建图形时,节点大小与传递给图形的大小列表不正确对应.有人可以帮忙吗?这是我正在使用的代码:
I am creating a networkX graph with the node sizes correlating to nodes. When I create the graph, the node sizes don't correspond correctly with the size list passed to the graph. Can anyone help? Here is the code I'm using:
import networkx as nx
G = nx.Graph()
nodelist = []
edgelist = []
sizes = []
for i in Results[0]:
if i > 0.10 and i != 1:
Normnodesize = (i/Maxcs)*800
Findnode = np.where(Results[0]==i)
nodelist.append(str(Findnode[0][0]))
edgelist.append((0,str(Findnode[0][0])))
sizes.append(int(Normnodesize))
G.add_nodes_from(nodelist)
G.add_edges_from(edgelist)
pos = nx.fruchterman_reingold_layout(G)
nx.draw_networkx(G,pos,node_size=sizes)
如果您查看节点,边缘,节点权重,则打印输出如下:
If you look at the nodes, edges, node weight the print out looks like:
16 (0, '16') 608
38 (0, '38') 732
55 (0, '55') 549
63 (0, '63') 800
66 (0, '66') 559
106 (0, '106') 693
117 (0, '117') 476
124 (0, '124') 672
130 (0, '130') 482
143 (0, '143') 518
列表中的节点大小和所示的节点大小不同,我不知道为什么.
The node sizes in the list and the node sizes depicted are not the same and I can't figure out why.
谢谢大家!
推荐答案
networkx将节点存储在字典中.当绘制它们时,它基本上按照python给定的顺序查看键.无法保证您将其权重放入sizes
的顺序相同.
networkx stores nodes in a dict. When it draws them, it basically looks at the keys in the order python gives. There's no guarantee that's the same order that you've put their weights into sizes
.
所以尝试:
nx.draw_networkx(G,pos,nodelist = nodelist, node_size=sizes)
这篇关于Networkx节点大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!