Improving Python NetworkX graph layout

前端 未结 4 1830
眼角桃花
眼角桃花 2020-12-07 11:07

I am having some problems in visualizing the graphs created with python-networkx, I want to able to reduce clutter and regulate the distance between the nodes (I have also t

4条回答
  •  不思量自难忘°
    2020-12-07 11:58

    To answer your question how to regulate the distance between nodes, I expand on Hooked's answer:

    If you draw the graph via the Graphviz backend and when you then use the fdp algorithm, you can adjust the distance between nodes by the edge attribute len.

    Here a code example, how to draw a graph G and save in the Graphviz file gvfile with wider distance between nodes (default distance for fdp is 0.3):

    A = nx.to_agraph(G)
    A.edge_attr.update(len=3)
    A.write(gv_file_name)
    

    Two comments:

    1. It is normally advisable to adjust len with the number of nodes in the graph.
    2. The len attribute is only recognised by the fdp and neato algorithm, but not e.g. by the sfdp algorithm.

提交回复
热议问题