html
Note
Click here <sphx_glr_download_sphinx_gallery_output_plot_12_multicomponent_graphs.py>
to download the full example code
sphx-glr-example-title
For each component, netgraph computes the node and edge layouts separately, and then arranges the individual components with respect to each other using rectangle packing.
/sphinx_gallery_output/images/sphx_glr_plot_12_multicomponent_graphs_001.png
import matplotlib.pyplot as plt
from itertools import combinations
from netgraph import Graph
edge_list = []
# add 15 2-node components
edge_list.extend([(ii, ii+1) for ii in range(30, 60, 2)])
# add 10 3-node components
for ii in range(60, 90, 3):
edge_list.extend([(ii, ii+1), (ii, ii+2), (ii+1, ii+2)])
# add a couple of larger components
n = 90
for ii in [10, 20, 30]:
edge_list.extend(list(combinations(range(n, n+ii), 2)))
n += ii
nodes = list(range(n))
Graph(edge_list, nodes=nodes, node_size=1, edge_width=0.3, node_layout='circular')
plt.show()
sphx-glr-timing
Total running time of the script: ( 0 minutes 1.262 seconds)
html
sphx-glr-signature