Python:如何在 Networkx 中聚合边缘标签

问题描述

我有一个如下所示的边示例,目前,我的 edge_labels 显示的是边 (a,b) 的最新“价格”为 200。

我想知道如何在绘制图形时对相同的边进行聚合。请看下图。

编辑:插图应该是有向图。所以700的价格应该包括a到b和b到a。

(a,b,price=500)
(a,price=100)
(b,c,a,price=100)

我的代码

df:
Date        debit credit price
2/4/2021      a      b     500
3/4/2021      a      b     100
3/4/2021      b      c     100
5/4/2021      b      a     100

G = nx.from_pandas_edgelist(df,'debit','credit',edge_attr='price',create_using=nx.DiGraph())

#Plot
edge_labels = nx.get_edge_attributes(G,'price')
nx.draw(G,pos,with_labels=True)
nx.draw_networkx_edge_labels(G,edge_labels=edge_labels)
plt.show()

networkx draw illustration

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)