我有一个有三种边的图:“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)
提前谢谢。在
本文介绍如何在Python中使用igraph库为有三种类型边的图(company, std, res)指定不同颜色。作者展示了创建边的代码,并提供了一个绘图函数,但该函数将所有边设为黑色。问题在于根据边的类型正确设置颜色的逻辑似乎不完整,作者寻求解决方案。"
93324285,8312087,Python实现决策树:审美决策模型,"['决策树python实现', '决策树分类', '机器学习模型', '数据科学', 'Python编程']
397

被折叠的 条评论
为什么被折叠?



