一种可能的 Select 是使用Connection styles for annotations.
您可以从以classic 方式绘制 node 开始:
fig, ax = plt.subplots(figsize=(4, 4))
nx.draw_networkx_nodes(
G, pos, ax=ax,
node_color="lime", alpha=0.4, edgecolors="black",
)
nx.draw_networkx_labels(G, pos, ax=ax)
然后分两步进行边缘处理,以实施connectionstyle
:
RADIUS = 1.2
EDGE_TO_BEND = (1, 3)
nx.draw_networkx_edges(
G, pos, ax=ax, edgelist=[e for e in G.edges() if e != EDGE_TO_BEND]
)
nx.draw_networkx_edges(
G, pos, ax=ax, edgelist=[EDGE_TO_BEND],
edge_color="tab:red", width=4, alpha=0.5,
arrows=True, connectionstyle=f"arc3,rad={RADIUS}",
)
ax.axis("off")
plt.show()
使用的图表(G
):
import networkx as nx
G = nx.Graph([(1, 2), (2, 3), (3, 4), (4, 1), (1, 3), (2, 4)])
pos = {1: (0, 1), 2: (1, 1), 3: (1, 0), 4: (0, 0)} # square-shape