使用注释的连接样式的一个可能选项。
您可以从绘制节点开始:
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)
然后分两步修边:
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="arc3,rad=1.2",
)
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)}