小编tim*_*ove的帖子

networkx - 根据边缘属性更改颜色/宽度 - 结果不一致

我设法正确生成了图形,但是对于以下两个不同的代码行,一些更多的测试结果表明结果不一致:

nx.draw_circular(h,edge_color=[h.edge[i][j]['color'] for (i,j) in h.edges_iter()], width=[h.edge[i][j]['width'] for (i,j) in h.edges_iter()])

nx.draw_circular(h,edge_color=list(nx.get_edge_attributes(h,'color').values()), width=list(nx.get_edge_attributes(h,'width').values()))
Run Code Online (Sandbox Code Playgroud)

第一行产生一致的输出,而第二行产生每个边缘的错误颜色/大小.

但是,它看起来我上面的两行都依赖于函数调用来返回每个边缘顺序的属性.为什么结果不同?

对我来说,访问属性看起来有点笨拙 h[][][]; 是否可以通过点约定访问它,例如edge.color for edge in h.edges().

或者我错过了什么?

python networkx python-3.x

33
推荐指数
2
解决办法
3万
查看次数

标签 统计

networkx ×1

python ×1

python-3.x ×1