import networkx as nx
import matplotlib.pyplot as plt
import matplotlib as mpl
G = nx.Graph()
edge_list = [(1,2), (1,3), (2,3), (3,4), (2,5), (3,5), (4,6), (5,7), (5,6), (7,8), (8,9), (7,9), (9,10), (10,11), (11,12), (6,11), (6,12), (13,14), (8,14), (10, 15), (14,15)]
G.add_edges_from(edge_list)
d=dict(G.degree)
low, *_, high = sorted(d.values())
norm = mpl.colors.Normalize(vmin=low, vmax=high, clip=True)
mapper = mpl.cm.ScalarMappable(norm=norm, cmap=mpl.cm.coolwarm)
nx.draw_circular(G,
nodelist=d,
node_size=1000,
node_color=[mapper.to_rgba(i)
for i in d.values()],
with_labels=True,
font_color='black')
plt.show()
print(f"Degree of node [1]: {dict(G.degree)[1]}")
print(f"Degree of node [2]: {dict(G.degree)[2]}")
print(f"Degree of node [3]: {dict(G.degree)[3]}")
print(f"Degree of node [4]: {dict(G.degree)[4]}")
print(f"Degree of node [5]: {dict(G.degree)[5]}")
print(f"Degree of node [6]: {dict(G.degree)[6]}")
print(f"Degree of node [7]: {dict(G.degree)[7]}")
print(f"Degree of node [8]: {dict(G.degree)[8]}")
print(f"Degree of node [9]: {dict(G.degree)[9]}")
print(f"Degree of node [10]: {dict(G.degree)[10]}")
print(f"Degree of node [11]: {dict(G.degree)[11]}")
print(f"Degree of node [12]: {dict(G.degree)[12]}")
print(f"Degree of node [13]: {dict(G.degree)[13]}")
print(f"Degree of node [14]: {dict(G.degree)[14]}")
print(f"Degree of node [15]: {dict(G.degree)[15]}")
print(nx.degree_centrality(G))
print(nx.closeness_centrality(G))
print(nx.betweenness_centrality(G))
print(nx.density(G))
print(nx.shortest_path(G, 1, 15))
print(nx.diameter(G))
plt.show()
Click Run or press shift + ENTER to run code