How to increase node spacing for networkx.spring_layout

前端 未结 3 829
滥情空心
滥情空心 2020-12-02 20:29

Drawing a clique graph with

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

produces the following picture:

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 20:58

    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

提交回复
热议问题