LaNet-vi#

LaNet-vi draws networks in concentric shells based on core number. This example compares a spring layout and a LaNet-vi plot of the same synthetic Internet topology.

import lanet_vi
import matplotlib.pyplot as plt
import networkx as nx

G = nx.random_internet_as_graph(2000, seed=7)
core = nx.core_number(G)

Compare the two layouts#

Both views use the k-core decomposition. In the spring layout, core number determines node color. In the LaNet-vi view, it also determines the shell where each node is placed.

fig, (left, right) = plt.subplots(1, 2, figsize=(16, 8), layout="constrained")
nx.draw(
    G,
    nx.spring_layout(G, seed=42),
    ax=left,
    node_size=5,
    node_color=[core[node] for node in G],
    cmap="viridis",
    edge_color="lightgray",
    width=0.3,
)
left.set_title("Spring layout colored by core number")

config = lanet_vi.LaNetConfig()
config.visualization.background = "white"
lanet_vi.draw(G, ax=right, config=config)
right.set_title("LaNet-vi shells by core number")
plt.show()
Spring layout colored by core number, LaNet-vi shells by core number

Verify the shell indices#

Check that LaNet-vi assigns the same core number as NetworkX to every node.

decomposition = lanet_vi.Network(G).decompose()
assert decomposition.node_indices == core

Total running time of the script: (0 minutes 9.778 seconds)

Gallery generated by Sphinx-Gallery