Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit vertex position in python graph-tool

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/

like image 540
Dilawar Avatar asked Oct 09 '11 14:10

Dilawar


1 Answers

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)
   ...
like image 108
Tiago Peixoto Avatar answered Sep 19 '22 01:09

Tiago Peixoto