import networkx as nx
import matplotlib.pyplot as plt
# 创建一个空的无向图
G = nx.Graph()
# 添加节点
G.add_nodes_from([1, 2, 3, 4, 5])
# 指定每个节点的位置
pos = {1: (0, 0),
2: (1, 1),
3: (2, 0),
4: (1, -1),
5: (-1, -1)}
# 添加边
G.add_edges_from([(1, 2), (1, 3), (1, 4), (1, 5)])
# 指定节点的颜色
node_colors = ['red' if node == 1 else 'blue' if node == 2 else 'lightblue' for node in G.nodes()]
# 绘制图形
nx.draw(G, pos, with_labels=True, node_size=500, node_color=node_colors, font_size=12, font_color='black')
# 显示图形
plt.show()