blob: 9d3e2a26896b9f8916678606c05e257a2a46bdd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
"""
=====================
Krackhardt Centrality
=====================
Centrality measures of Krackhardt social network.
"""
import matplotlib.pyplot as plt
import networkx as nx
G = nx.krackhardt_kite_graph()
print("Betweenness")
b = nx.betweenness_centrality(G)
for v in G.nodes():
print(f"{v:2} {b[v]:.3f}")
print("Degree centrality")
d = nx.degree_centrality(G)
for v in G.nodes():
print(f"{v:2} {d[v]:.3f}")
print("Closeness centrality")
c = nx.closeness_centrality(G)
for v in G.nodes():
print(f"{v:2} {c[v]:.3f}")
pos = nx.spring_layout(G, seed=367) # Seed layout for reproducibility
nx.draw(G, pos)
plt.show()
|