本文介绍了使用NetworkX导出图形的布局位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在NetworkX中生成图形的x / y布局坐标后,如何使用类似GraphML的东西将图形连同节点位置一起导出为节点定义的一部分?布局算法似乎没有直接注释图形?或者它们是什么?!
解决方案
布局算法不设置节点属性(但它们应该)。以下是如何设置属性:
In [1]:import networkx as nx
In [2]:G = nx.path_graph(4)
在[3]中:pos = nx.spring_layout(G)
In [4]:nx.set_node_attributes( G,'pos',pos)
在[5]中:G.node
Out [5]:
{0:{'pos':array([0。 ,'b'b}:{'pos':array([0.32267963,0.03340727])},
2:{'pos':array([0.67729057,0.07011044])},
3:{'pos':array([1.,0.10350174])}}
After generating x/y layout coordinates for a graph in NetworkX, how do I export the graph, along with node positions, as part of the node definition using something like GraphML?
The layout algorithms don't seem to annotate the graph directly? Or do they?!
解决方案
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])}}
这篇关于使用NetworkX导出图形的布局位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!