是否有在边缘中间绘制带箭头的边缘的功能?
is there an function that draw an edge with arrow in the middle of the edge?
我想画一条边,中间有一个箭头。
我将 networkx 与 python 3.6 和 mathblotlib 一起用于显示图形。
我尝试了很多方法,但我刚收到这个结果。
predecesseur={'1': nan, '2': nan, '3': '1', '4': '1,2', '5': '3,4'}
tachdu={'1': '2', '2': '4', '3': '4', '4': '5', '5': '6'}
G=nx.DiGraph()
G.add_node('Début',type ='0')
G.add_node('Fin',type ='0')
for key in predecesseur.keys():
G.add_node(key,type =tachdu[key])
ch=predecesseur[key]
if type(ch)!=type(0.0):
for i in range(len(ch)):
if (ch[i]!=',' and ch[i]!=';'):
G.add_edge(ch[i],key)
else:
G.add_edge('Début',key)
for nod in G:
if list(G.successors(nod))==[]:
G.add_edge(nod,'Fin')
pos_nodes = nx.spring_layout(G)
nx.draw(G, pos_nodes, with_labels=True)
color_map = ['green']
nx.draw_networkx_nodes(G, pos_nodes, node_size=500, nodelist=['Fin'],node_color=color_map)
nx.draw_networkx_nodes(G, pos_nodes, node_size=1400, nodelist=['Début'],node_color=color_map)
node_attrs = nx.get_node_attributes(G, 'type')
pos_attrs = {}
for node, coords in pos_nodes.items():
pos_attrs[node] = (coords[0], coords[1] + 0.08)
custom_node_attrs = {}
for node, attr in node_attrs.items():
custom_node_attrs[node] = "{" + attr + "}"
nx.draw_networkx_labels(G, pos_attrs, labels=custom_node_attrs)
plt.show()
Networkx 使用 Matplotlib 绘制图形。对于边,它使用 ArrowStyle。以下是可能的边类型:
所以不,networkx 不能在边的中间绘制箭头。您可以尝试将其转换为 DOT 格式(或任何其他格式)并尝试使用其他工具对其进行可视化。
我想画一条边,中间有一个箭头。 我将 networkx 与 python 3.6 和 mathblotlib 一起用于显示图形。
我尝试了很多方法,但我刚收到这个结果。
predecesseur={'1': nan, '2': nan, '3': '1', '4': '1,2', '5': '3,4'}
tachdu={'1': '2', '2': '4', '3': '4', '4': '5', '5': '6'}
G=nx.DiGraph()
G.add_node('Début',type ='0')
G.add_node('Fin',type ='0')
for key in predecesseur.keys():
G.add_node(key,type =tachdu[key])
ch=predecesseur[key]
if type(ch)!=type(0.0):
for i in range(len(ch)):
if (ch[i]!=',' and ch[i]!=';'):
G.add_edge(ch[i],key)
else:
G.add_edge('Début',key)
for nod in G:
if list(G.successors(nod))==[]:
G.add_edge(nod,'Fin')
pos_nodes = nx.spring_layout(G)
nx.draw(G, pos_nodes, with_labels=True)
color_map = ['green']
nx.draw_networkx_nodes(G, pos_nodes, node_size=500, nodelist=['Fin'],node_color=color_map)
nx.draw_networkx_nodes(G, pos_nodes, node_size=1400, nodelist=['Début'],node_color=color_map)
node_attrs = nx.get_node_attributes(G, 'type')
pos_attrs = {}
for node, coords in pos_nodes.items():
pos_attrs[node] = (coords[0], coords[1] + 0.08)
custom_node_attrs = {}
for node, attr in node_attrs.items():
custom_node_attrs[node] = "{" + attr + "}"
nx.draw_networkx_labels(G, pos_attrs, labels=custom_node_attrs)
plt.show()
Networkx 使用 Matplotlib 绘制图形。对于边,它使用 ArrowStyle。以下是可能的边类型:
所以不,networkx 不能在边的中间绘制箭头。您可以尝试将其转换为 DOT 格式(或任何其他格式)并尝试使用其他工具对其进行可视化。