rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

[joss] Default graph layout does not handle disconnected graphs well

Open szhorvat opened this issue 3 years ago • 1 comments

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))
image

szhorvat avatar Dec 04 '21 22:12 szhorvat

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)
Στιγμιότυπο 2021-12-05, 1 02 50 μμ

georgios-ts avatar Dec 05 '21 11:12 georgios-ts