如何解决Python networkx:如何在粗线上获得非圆形箭头?
我正在使用 networkx 在 Python 中绘制有向图。我使用不同宽度的边缘来突出重量。不幸的是,箭头是圆形的,看起来很奇怪。我想为看起来像细线箭头的缩放版本的粗线绘制非圆形箭头。
import networkx as nx
import matplotlib.pyplot as plt
import numpy
G=nx.DiGraph()
stake = [
[0,1,3],[3,1],[0,[1,3,0]
]
maxS = max(max(stake))
stake1d = numpy.concatenate(stake)
minS = min(stake1d[numpy.nonzero(stake1d)])
minLineWeight = 1
maxLineWeight = 10
for x in range(len(stake)):
for y in range(x):
if(stake[x][y] > 0):
weight = (stake[x][y] - minS) / (maxS - minS) * (maxLineWeight - minLineWeight) + minLineWeight
G.add_edge(x,y,weight=weight,color='r')
for x in range(len(stake)):
for y in [i for i in range(len(stake))][-(len(stake)-x):]:
if(stake[x][y] > 0):
weight = (stake[x][y] - minS) / (maxS - minS) * (maxLineWeight - minLineWeight) + minLineWeight
G.add_edge(x,color='b')
weights=list(nx.get_edge_attributes(G,'weight').values())
colors=list(nx.get_edge_attributes(G,'color').values())
pos = nx.shell_layout(G)
nx.draw(
G,pos=pos,width=weights,edge_color=colors,with_labels=True,arrows=True,connectionstyle='arc3',arrowstyle='->'
)
plt.show()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。