【发布时间】:2023-04-07 16:58:01
【问题描述】:
我创建了一个 networkX 加权图(有关代码,请参阅 this question),我想根据节点颜色对边进行颜色编码。如果两个节点的颜色相同并且连接,我希望它们的边缘颜色是一种颜色,比如红色。此外,如果节点的颜色不同但连接在一起,我希望它们是不同的颜色,比如蓝色。有什么方法可以实现吗?
边缘的代码如下:
for edge in G.edges():
source, target = edge
rad = 0.35
arrowprops=dict(lw=G.edges[(source,target)]['weight'],
arrowstyle="-",
color='blue',
connectionstyle=f"arc3,rad={rad}",
linestyle= '-',
alpha=0.6)
ax.annotate("",
xy=pos[source],
xytext=pos[target],
arrowprops=arrowprops
)
【问题讨论】:
标签: python matplotlib networkx