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:
For some of the layout algorithms there is a "scale" parameter that might help. e.g.
In 1: import networkx as nx
In 2: G=nx.path_graph(4)
In [3]: pos=nx.spring_layout(G) #default to scale=1
In [4]: nx.draw(G,pos)
In [5]: pos=nx.spring_layout(G,scale=2) # double distance between all nodes
In [6]: nx.draw(G,pos)
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:
Tweak with these parameters to see how it works. But despite this there is no guarantee that all nodes are non-overlapping
I used the optimal distance parameter of the Kamada Kawai layout, and set the distance between non-connected components to the maximum distance in the graph. There is probably a better way of munging the dictionaries, but this is pretty easy: