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/
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)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With