Exporting Layout Positions for a Graph Using NetworkX

扶醉桌前 提交于 2019-11-29 07:03:45

The layout algorithms don't set node attributes (but they should). Here is how to set the attributes:

In [1]: import networkx as nx

In [2]: G=nx.path_graph(4)

In [3]: pos=nx.spring_layout(G)

In [4]: nx.set_node_attributes(G,'pos',pos)

In [5]: G.node
Out[5]: 
{0: {'pos': array([ 0.,  0.])},
 1: {'pos': array([ 0.32267963,  0.03340727])},
 2: {'pos': array([ 0.67729057,  0.07011044])},
 3: {'pos': array([ 1.        ,  0.10350174])}}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!