Using vertex index inside label

I would like to combine an existing vertex property (called labelv and of type string) and the vertex index to obtain a new vertex property, to use inside graphviz_draw. Here is what I wrote:

mylabel = g.new_vertex_property("string")
for v in g.vertices():
  g.vp['mylabel'][v] = str(g.vp['labelv'][v])+" ("+str(g.vertex_index[v])+")"

graphviz_draw(g, vcolor=typev, gprops={"scalexy": "scalexy"}, \
vprops={"xlabel": mylabel, "fontsize": 6, "fixedsize": True, \
"labelloc": "t"}, eprops={"label": labele, "fontsize": 4, \
"dir": "forward"}, output=fname+".pdf »)

But it doens’t work. (I get the error message:

Traceback (most recent call last):
  File "build-graph.py", line 380, in <module>
    g.vp['mylabel'][v] = str(g.vp['labelv'][v])+" ("+str(g.vertex_index[v])+")"
  File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 1346, in __getitem__
    return self.properties[(self.t, key)]
KeyError: ('v', 'mylabel’)

Could you tell me what I’m doing wrong?

Thanks!

attachment.html (2.87 KB)

Property maps do not automatically show up in the internal
dictionary. Here it should be simply:

    mylabel = g.new_vertex_property("string")
    for v in g.vertices():
       mylabel[v] = str(g.vp['labelv'][v])+" ("+str(g.vertex_index[v])+")"

or alternatively, you should store the property in the dictionary first:

    g.vp["mylabel"] = mylabel

Best,
Tiago