Explicit vertex position in python graph-tool
Asked Answered
U

1

7

I am using python graph-tool. To draw graphs, it uses graph_draw function. I want to send vertex positions explicitly to dot engine. It turns out that I can pass a property map named pos. I tried defining it as v_pos = g.new_vertex_property("vector<double>") where g is my graph. I am not sure if it is the right way to do it.

There is one code snippet which you might find helpful.

pos = gt.random_layout(g, shape=shape, dim=3)
>>> pos[g.vertex(0)].a
array([ 86.59969709,   1.31435598,   0.64651486])
graph_draw(g, pos=pos, output="graph-draw-random.pdf")

What should I do if I were to define my vertex position at (0,2), (0,4) ... (0,8)?

In above code snippet, I can change dim to 2. But I don't want random layout.

For reference, here is the home-page of this tool I am using. http://projects.skewed.de/graph-tool/

Ulberto answered 9/10, 2011 at 14:42 Comment(0)
R
7

You can set the positions trivially as follows:

   pos = g.new_vertex_property("vector<double>")
   pos[g.vertex(0)] = (0, 2)
   pos[g.vertex(1)] = (0, 4)
   ...
Rossner answered 9/4, 2012 at 13:33 Comment(1)
im getting below error while running second line, ValueError: Invalid vertex index: 0Dato

© 2022 - 2024 — McMap. All rights reserved.