绘制具有平行边缘的igraph图,没有边缘的叠加

时间:2017-01-31 17:47:57

标签: python plot igraph

我有一个图形,顶点之间有多条边,如下所示:

IGRAPH U-W- 5 10 --
+ attr: id (v), label (v), weight (e)
+ edges:
0 -- 1 1 2 3       2 -- 0 1 3         4 -- 1 3
1 -- 0 0 2 3 3 4   3 -- 0 1 1 2 4

edgeWeights = [10, 7, 9, 6, 9, 11, 8, 8, 5, 7]

我想绘制此图表,在边缘显示属性权重的值,但会出现平行边缘的叠加。下面的代码用于绘制图表。

def graphVisualization(graph, clusters):
    member = clusters.membership
    if member is not None:
        gcopy = graph.copy()
        edges = []
        edges_colors = []
        for edge in graph.es():
            if member[edge.tuple[0]] != member[edge.tuple[1]]:
                edges.append(edge)
                edges_colors.append("red")
            else:
                edges_colors.append("black")
        gcopy.delete_edges(edges)
        layout = gcopy.layout("kk")
        graph.es["color"] = edges_colors
    else:
        layout = graph.layout("ba")
        graph.es["color"] = "gray"
    visual_style = {}
    visual_style["vertex_label_dist"] = 0
    visual_style["edge_curved"] = False
    visual_style["vertex_shape"] = "circle"
    visual_style["edge_color"] = graph.es["color"]
    visual_style["vertex_size"] = 30
    visual_style["layout"] = layout
    visual_style["margin"] = 40

    graph.vs["label"] = range(0, graph.vcount())
    graph.es["label"] = graph.es.get_attribute_values("weight")

    if member is not None:
        colors = []
        for i in range(0, max(member)+1):
            colors.append('%06X' % randint(0, 0xFFFFFF))
        for vertex in graph.vs():
            vertex["color"] = str('#') + colors[member[vertex.index]]
        visual_style["vertex_color"] = graph.vs["color"]
    plot(graph, **visual_style)

下图显示了绘制的图表。 enter image description here

如何在不叠加egdes的情况下绘制图形?

带有autocurve参数的图表。

enter image description here

0 个答案:

没有答案