Hi all,
Today I need to know how, in a directed graph, I can color a directed edge by the color of the target node.
In this example
f = Graph(directed=True) f.add_edge_list([[0, 1], [0, 2], [1, 2]]) partition = f.new_vertex_property('int') blocks = [0, 0, 1] for i in range(0, 3): partition[f.vertex(i)] = blocks[i] graph_draw(f, vertex_fill_color=partition)
vertices 0 and 1 have the color of partition 0 and vertex 2 has the color of partition 1.
Accordingly,
edge (0, 1) should have the same color as block 0, edge (0, 2) should have the same color as block 1 and edge (1, 2) should have the same color as block 1.
Thanks again
Haiko
Am 24.09.18 um 23:57 schrieb Lietz, Haiko:
Today I need to know how, in a directed graph, I can color a directed edge by the color of the target node.
You can propagate vertex properties to edges with the function edge_endpoint_property(), e.g.
epartition = edge_endpoint_property(g, partition, "target")
This will propagate the partition value of the target node to the edge, as an edge property map. You then can pass this to "edge_color" in graph_draw().
Best, Tiago
Very nice!
This is a working example:
f = Graph(directed=True) f.add_edge_list([[0, 1], [0, 2], [1, 2]]) partition = f.new_vertex_property('int') blocks = [0, 0, 1] for i in range(0, 3): partition[f.vertex(i)] = blocks[i] epartition = edge_endpoint_property(f, partition, 'target') graph_draw(f, vertex_fill_color=partition, edge_color=epartition)
Thx
Haiko