Color edge by target node color

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

attachment.html (1.28 KB)

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