6.1(学号:3025)

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()

nodes = ['v1', 'v2', 'v3', 'v4', 'v5', 'v6']
G.add_nodes_from(nodes)

edges = [
('v1', 'v2'), ('v1', 'v3'), ('v1', 'v4'),
('v2', 'v3'), ('v2', 'v6'),
('v3', 'v4'),
('v4', 'v5'),
('v5', 'v6')
]
G.add_edges_from(edges)

pos = nx.circular_layout(G)

center = (0, 0)
pos['v1'] = center

plt.figure(figsize=(8, 8))
nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=700, font_size=15, font_weight='bold')
plt.title("Undirected Graph as Described")
plt.axis('equal')
plt.show()

print("学号:3025")

posted @ 2024-10-27 21:28  唐锦珅  阅读(1)  评论(0编辑  收藏  举报