如何在networkx中自定义边缘标签的显示? [英] How do I customize the display of edge labels in networkx?

查看:767
本文介绍了如何在networkx中自定义边缘标签的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个具有边属性(例如r,例如r=23)的图.

I create a graph with edge attributions (say r, such as, r=23).

如何仅使用值23而不是{'r':'23'}显示边缘标签.

How do display edge labels only with the values, 23 instead of {'r':'23'}.

相关的源代码如下:

# build a graph
G.add_edge(u, v, r=value)

# plot the graph
pos = nx.spring_layout(G, scale=2)

nx.draw(G, pos)

edge_labels = nx.get_edge_attributes(G,'r')
nx.draw_networkx_edge_labels(G, pos, labels = edge_labels)

plt.savefig(out_file)

推荐答案

命令draw_networkx_edge_labels需要参数edge_labels而不是`labels.

The command draw_networkx_edge_labels needs the argument edge_labels rather than `labels.

因此您需要将nx.draw_networkx_edge_labels(G, pos, labels = edge_labels)更改为nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels)

这篇关于如何在networkx中自定义边缘标签的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆