Explicit vertex position in python graph-tool

烂漫一生 提交于 2020-01-13 10:00:11

问题


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/


回答1:


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)
   ...


来源:https://stackoverflow.com/questions/7704281/explicit-vertex-position-in-python-graph-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!