经过一番研究,我发现答案是正确的
nx.set_node_attributes()。
当然可以将节点位置分配为属性:
pos={'0':(1,0),'1':(1,1),'2':(2,3),'3':(3,2),'4':(0.76,1.80),'5':(0,2)} nx.set_node_attributes(G, pos, 'coord')导致
In[1]: G.nodes(data=True)Out[1]:[('1', {'coord': (1, 1)}), #each node has its own position ('0', {'coord': (1, 0)}), ('3', {'coord': (3, 2)}), ('2', {'coord': (2, 3)}), ('5', {'coord': (0, 2)}), ('4', {'coord': (0.76, 1.8)})]并且还可以使用专用字典(在这种情况下
test)附加多个属性,而不必与其中的节点拥有相同数量的元素
G(例如,可以有 没有 属性的节点):
test={'0':55,'1':43,'2':17,'3':86,'4':2} #node '5' is missingnx.set_node_attributes(G, 'test', test)导致
In[2]: G.nodes(data=True)Out[2]:[('1', {'coord': (1, 1), 'test': 43}), ('0', {'coord': (1, 0), 'test': 55}), ('3', {'coord': (3, 2), 'test': 86}), ('2', {'coord': (2, 3), 'test': 17}), ('5', {'coord': (0, 2)}), ('4', {'coord': (0.76, 1.8), 'test': 2})]我推测使用可以对图形边缘进行同样的处理
nx.set_edge_attributes()。



