Qiskit / rustworkx

A high performance Python graph library implemented in Rust.
https://www.rustworkx.org
Apache License 2.0
1.09k stars 150 forks source link

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

Open szhorvat opened 2 years ago

szhorvat commented 2 years ago

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
georgios-ts commented 2 years ago

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 μμ