[英]networkx draw nodes on a line in order with curved edges
您可以通过将节点位置 (x,y) 的字典传递给nx.draw
函数来控制节点的位置(请参阅此处的文档)。 要将曲线添加到箭头,您可以在nx.draw
函数中使用connectionstyle='arc3,rad=-0.7'
( rad
为曲线取任何值)(请参阅此处的文档)。
请参见下面的示例:
import networkx as nx
import matplotlib.pyplot as plt
G=nx.DiGraph()
N_nodes=7
[G.add_node(i) for i in range(N_nodes)]
G.add_edge(0,1)
G.add_edge(2,4)
G.add_edge(2,5)
posx=[0,1,3,5,6,7,9]
posy=N_nodes*[0]
pos={i:[posx[i],posy[i]] for i in range(N_nodes)}
nx.draw(G,pos=pos,connectionstyle="arc3,rad=-0.7",edge_color='blue')
plt.ylim([-0.5,0.5])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.