使用 Networkx,我有几个需要以不同方式显示的边。为此,我使用了连接样式,有些边是直线,有些是 Arc3。问题是每条边都有一个标签,并且标签不跟随这些样式中的边。
我借了一张图作为例子:
#!/usr/bin/env python3
import networkx as nx
import matplotlib.pyplot as plt
# Graph data
names = ['A', 'B', 'C', 'D', 'E']
positions = [(0, 0), (0, 1), (1, 0), (0.5, 0.5), (1, 1)]
edges = [('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 'E'), ('D', 'A')]
# Matplotlib figure
plt.figure('My graph problem')
# Create graph
G = nx.MultiDiGraph(format='png', directed=True)
for index, name in enumerate(names):
G.add_node(name, pos=positions[index])
labels = {}
for edge in edges:
G.add_edge(edge[0], edge[1])
labels[(edge[0], edge[1])] = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 python 中的networks.draw() 函数绘制图形。尽管它不是有向图,但我的图的边缘按拓扑排序顺序排列。我想打印看起来像依赖 DAG 的图表以获得更好的可见性。目标是这样的:
我该怎么做?