本文介绍了如何增加networkx.spring_layout的节点间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

 >将networkx导入为nx 
....
nx。 draw(G,layout = nx.spring_layout(G))

产生下图:





显然,节点之间的间隔(例如边缘长度)需要增加。我已使用Google搜索并找到这里:

但是,比例参数不会似乎有任何影响。



获得更好绘图的正确方法是什么?

解决方案

好的,我的回答对于这个问题来说太晚了。但是这个问题的解决方案在于尚未发布的NetworkX 1.8版本,但可通过git hub获得。



执行以下操作以增加节点之间的距离:

  pos = nx.spring_layout(G,k = 0.15,迭代= 20)
#k控制节点之间的距离并且在0和1之间变化
#迭代次数是模拟退火运行的次数
#default k = 0.1和迭代= 50

调整这些参数以查看它是如何工作的。但是,尽管如此,并不能保证所有节点都不重叠

Drawing a clique graph with

import networkx as nx
....
nx.draw(G, layout=nx.spring_layout(G))

produces the following picture:

Obviously, the spacing between the nodes (e.g., the edge length) needs to be increased. I've googled this and found this suggestion here:

However, the scale parameter does not seem to have any effect.

What is the right method to get a better drawing?

解决方案

Alright, my answer is too late for this question. But the solution to this problem lies in the NetworkX version 1.8 which is yet to be released, but is available via git hub.

Do the following to increase the distance between nodes:

    pos = nx.spring_layout(G,k=0.15,iterations=20)
    # k controls the distance between the nodes and varies between 0 and 1
    # iterations is the number of times simulated annealing is run
    # default k =0.1 and iterations=50

Tweak with these parameters to see how it works. But despite this there is no guarantee that all nodes are non-overlapping

这篇关于如何增加networkx.spring_layout的节点间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:30