python不同颜色的边_如何在Python中使用igraph为不同的边指定不同的颜色?

我有一个有三种边的图:“company”、“std”和“res”。许多其他顶点没有边。在

当我绘制摘要时,我得到:IGRAPH UN-- 500 36 --

+ attr: area (v), cnpj (v), grande_area (v), name (v), res (v), std (v), company (e), res (e), std (e)

我想用不同的颜色绘制不同类型的边,但我找不到正确的代码。在

下面是我打印边缘时得到的示例:

^{pr2}$

我用来做边缘的代码是:def edge_group(g):

for v in g.vs:

for w in g.vs:

if v != w:

if g.are_connected(v, w) is False:

if v['name'].get_cnpj() != "":

if v["name"].get_cnpj() == w["name"].get_cnpj():

g.add_edge(v, w, company=True)

if len(set(v['std']).intersection(w['std'])) > 0:

g.add_edge(v, w, std=True)

if len(set(v['res']).intersection(w['res'])) > 0:

g.add_edge(v, w, res=True)

return g

这是给我所有边缘“黑色”的代码def drawing_group(g):

layout = g.layout("fr")

visual_style = {}

visual_style["vertex_size"] = 1

if g.es["company"] is True and g.es['res'] is True and g.es['std'] is True:

visual_style['edge_color'] = 'black'

if g.es["company"] is True and g.es['res'] is True:

visual_style['edge_color'] = 'grey'

if g.es["company"] is True and g.es['std'] is True:

visual_style['edge_color'] = 'green'

if g.es['company'] is True:

visual_style['edge_color'] = 'blue'

if g.es['res'] is True and g.es['std'] is True:

visual_style['edge_color'] = 'red'

if g.es['res'] is True:

visual_style['edge_color'] = 'yellow'

if g.es['std'] is True:

visual_style['edge_color'] = 'brown'

visual_style["layout"] = layout

visual_style["bbox"] = (500, 500)

visual_style["margin"] = 20

visual_style['hovermode'] = 'closest'

igraph.plot(g, 'output/gr_%s.png' % num, **visual_style)

提前谢谢。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值