7.5 KiB
7.5 KiB
In [ ]:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edges_from([
('Alice', 'Bob'), ('Alice', 'Emma'),
('Bob', 'Chloé'), ('Bob', 'Félix'),
('Chloé', 'David'), ('Chloé', 'Gaël')
])
plt.figure(figsize=(6,4))
pos = nx.spring_layout(G, seed=0)
nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=1000)
plt.show()In [ ]:
centralite_degre = nx.degree_centrality(G)
for personne, c in sorted(centralite_degre.items(), key=lambda x: -x[1]):
print(f"{personne} : {round(c, 2)}")In [ ]:
centralite_proximite = nx.closeness_centrality(G)
for personne, c in sorted(centralite_proximite.items(), key=lambda x: -x[1]):
print(f"{personne} : {round(c, 2)}")In [ ]:
centralite_intermediarite = nx.betweenness_centrality(G)
for personne, c in sorted(centralite_intermediarite.items(), key=lambda x: -x[1]):
print(f"{personne} : {round(c, 2)}")