spine_network_plot¶
Draw a network with its nodes coloured by score.
The natural pairing is the degree measure with "upper", where the hubs
are the atypical nodes. Nodes are sized by degree so hubs read as hubs, and
drawn in increasing order of score so they are never buried. Edges are kept
faint: the point is which nodes stand out, not the wiring.
Syntax and options¶
from entropy_spine import spine_network_plot
help(spine_network_plot)
Help on function spine_network_plot in module entropy_spine.interface.plots:
spine_network_plot(
result,
A,
*,
title: 'str' = '',
colour_by: 'str' = 'score',
seed: 'int' = 0,
label_top: 'int' = 0,
edge_alpha: 'float' = 0.12
)
Draw a network with its nodes coloured by score.
The natural pairing is the ``degree`` measure with ``"upper"``, where the
hubs are the atypical nodes. Nodes are laid out by a seeded deterministic
force layout, drawn in increasing order of score so the atypical ones sit
on top, and sized by degree so hubs read as hubs. Edges are kept faint:
the point is which nodes stand out, not the wiring. Returns the figure.
Hubs in a small-world network¶
A ring lattice with a few shortcuts, plus five nodes wired to a fifth of the network each.
%matplotlib inline
import numpy as np
from entropy_spine import spine, spine_network_plot
rng = np.random.default_rng(7)
n, n_hub = 120, 5
W = np.zeros((n + n_hub, n + n_hub))
for i in range(n):
for j in range(1, 4):
t = (i + j) % n
W[i, t] = W[t, i] = 1
for h in range(n_hub):
targets = rng.permutation(n)[: n // 5]
W[n + h, targets] = W[targets, n + h] = 1
s, r = spine(W, "degree", "upper")
print(f"{W.shape[0]} nodes, {r.n_strata} strata, "
f"{int(np.sum(s > 0))} flagged as hubs")
spine_network_plot(r, W, title="designated hubs", seed=3);
125 nodes, 2 strata, 5 flagged as hubs
A network with no hubs¶
One stratum, nothing flagged. That is a property of the network: these degrees sit at a single scale.
W_flat = W[:n, :n]
sf, rf = spine(W_flat, "degree", "upper")
print(f"degrees {int(W_flat.sum(1).min())} to {int(W_flat.sum(1).max())}, "
f"{rf.n_strata} stratum, {int(np.sum(sf > 0))} flagged")
degrees 6 to 6, 1 stratum, 0 flagged