自定义节点位置#

绘制一个节点位于用户定义位置的图。

当用户设置一个位置时,其他节点仍然可以在布局中整齐地组织。

plot center node
import networkx as nx
import numpy as np

G = nx.path_graph(20)  # An example graph
center_node = 5  # Or any other node to be in the center
edge_nodes = set(G) - {center_node}
# Ensures the nodes around the circle are evenly distributed
pos = nx.circular_layout(G.subgraph(edge_nodes))
pos[center_node] = np.array([0, 0])  # manually specify node position
nx.draw(G, pos, with_labels=True)

脚本总运行时间: (0 minutes 0.047 seconds)

由 Sphinx-Gallery 生成的图集