将边缘权重传递给networkx中的graphviz_layout [英] Passing edge weights to graphviz_layout in networkx
问题描述
每个人都找不到如何将权重列表的属性名称传递给networkx中的graphviz_layout.像这样:
everybody cannot find how to pass name of property of list of weights to graphviz_layout in networkx. Something like this:
nx.spring_layout(G, weight='weight.sum')
,但带有nx.graphviz_layout(G, ...)
.也许有人会知道吗?
but with nx.graphviz_layout(G, ...)
. Maybe somebody will know?
推荐答案
如果我对,您想指定哪个edge属性用作graphviz布局的边缘权重.从 NetworkX文档中我看不到这个可能.
If I got you right, you want to specify which edge attribute to use as edge weight for the graphviz layout. From the NetworkX docs I don't see that this is possible.
但是,graphciz中的布局算法使用weight
属性.这就是它的意思:
However, the weight
attribute is used by the layout algorithms in graphviz. This is what it says:
边缘的重量.以点为单位,重量越重,边缘越短,越直和越垂直.对于其他布局,较大的权重鼓励布局使边缘长度更接近 len 属性.
Weight of edge. In dot, the heavier the weight, the shorter, straighter and more vertical the edge is. For other layouts, a larger weight encourages the layout to make the edge length closer to that specified by the len attribute.
使用此方法,您可以设置网络中每个边缘的边缘权重:>
With this you can set the edge weight for each edge in the network:
g = nx.Graph()
g.add_edge(1, 2, {'weight': 4})
或
g.add_edge(1, 2)
g.edge[1][2]['weight'] = 4
或
g[1][2]['weight'] = 4
如果要为边缘设置默认权重,则可以将其作为 argument传递给graphviz程序您要在graphviz_layout
中使用的:
If you want to set a default weight for the edges, you can pass this as an argument to the graphviz program that you want to use in graphviz_layout
:
nx.graphviz_layout(g, prog='dot', args='-Eweight=4')
这篇关于将边缘权重传递给networkx中的graphviz_layout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!