rustworkx
rustworkx copied to clipboard
[joss] Default graph layout does not handle disconnected graphs well
The default layout used by the plotting function mpl_draw
does not handle disconnected graphs very well. The distance between the components is very large, making it impossible to see the structure of the components themselves.
mpl_draw(rx.undirected_gnm_random_graph(20,15, seed=1234))

In mpl_draw
we use spring_layout
https://qiskit.org/documentation/retworkx/stubs/retworkx.spring_layout.html#retworkx.spring_layout with default values which isn't always ideal. With a little experimentation, you can get a nicer output:
graph = rx.undirected_gnm_random_graph(20, 15, seed=1234)
pos = rx.spring_layout(graph, k=1.0, seed=1234)
mpl_draw(graph, pos=pos)
