Networks can also be classified by how centralized they are—how much of their centrality is concentrated in one or a few nodes. Unequal distributions are more centralized. As an example, the most centralized network would be all nodes connected to a single hub node.
The following code plots histograms of the eigenvector centralities for each of the example networks:
# Function to plot a single histogram
def centrality_histogram(x, title=None):
plt.hist(x, density=True)
plt.title(title)
plt.xlabel("Centrality")
plt.ylabel("Density")
# Create a figure
plt.figure(figsize=(7.5, 2.5))
# Calculate centralities for each example and plot
plt.subplot(1, 3, 1)
centrality_histogram(
nx.eigenvector_centrality(G_karate).values(), title="Karate")
plt.subplot(1, 3, 2)
centrality_histogram(
nx.eigenvector_centrality...