Using the values of a property (eg. g.edge_index)

Hey there,

I have a list of labels which I'd like to attach to the rendering of a
graph. I can get a PDF with labels on the edges using:

import graph_tool.all as gt
[[[make graph g with vertices and edges]]]
gt.graphviz_draw(g, eprops={"label":g.edge_index},output="out.pdf")
#produces a graph with edges labeled 0 to n-1
gt.graphviz_draw(g, eprops={"label":"test label"},output="out.pdf")
#produces a graph with all edges labeled "test label", so labeling with
strings is possible

What I'd like to do is to use those edge_index values as index for an arary
containing my labels as strings to be placed in the graph.

eprops={"label":labelStrings[i]} # where i is equal to the numeric value of
the edge_index

How would I do that?

edge_index is a PropertyMap so that can't be used as index, but getting the
values out as an array fails too so apparently it is of type vector or
object.

Perhaps if I could see what a 'vector' is as defined here I might be able to
figure it out, but it's not specified:
http://projects.skewed.de/graph-tool/doc/graph_tool.html#graph_tool.PropertyMap

Being able to assign a label at the moment the edge is created with add_egde
would work too and is even preferable in my situation, so that might be a
solution too if I'd know how.

Thanks,
Jelle

Hi Jelle,

Hey there,

I have a list of labels which I'd like to attach to the rendering of a
graph. I can get a PDF with labels on the edges using:

import graph_tool.all as gt
[[[make graph g with vertices and edges]]]
gt.graphviz_draw(g, eprops={"label":g.edge_index},output="out.pdf")
#produces a graph with edges labeled 0 to n-1
gt.graphviz_draw(g, eprops={"label":"test label"},output="out.pdf")
#produces a graph with all edges labeled "test label", so labeling with
strings is possible

What I'd like to do is to use those edge_index values as index for an

arary

containing my labels as strings to be placed in the graph.

eprops={"label":labelStrings[i]} # where i is equal to the numeric

value of

the edge_index

How would I do that?

All you have to do is to create an edge property map with a value type
'string':

label = g.new_edge_property("string")

e = g.add_edge(s, t)
label[e] = "label for new edge"

graphviz_draw(g, eprops={"label": label})

Perhaps if I could see what a 'vector' is as defined here I might be

able to

figure it out, but it's not specified:

http://projects.skewed.de/graph-tool/doc/graph_tool.html#graph_tool.PropertyMap

A vector in this context is a C++ vector which is reflected into
python. This refers to the type the property map stores, rather than the
property map itself.

Cheers,
Tiago

Great, thanks for the quick response again!