python图形工具中的显式顶点位置 [英] Explicit vertex position in python graph-tool

查看:227
本文介绍了python图形工具中的显式顶点位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python图形工具。要绘制图形,它使用 graph_draw 功能。我想明确地发送顶点位置到点引擎。事实证明,我可以传递名为 pos 的属性映射。我尝试将其定义为 v_pos = g.new_vertex_property(vector< double>),其中 g 是我的图形。我不确定这是否是正确的方法。



有一个代码片段,您可能会发现它有帮助。

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

如果我要在(0,2),(0, 4)...(0,8)?



在上面的代码片段中,我可以将dim改为2,但我不想随机布局。 >

作为参考,这里是我正在使用的这个工具的主页。 http://projects.skewed.de/graph-tool/

解决方案

您可以按以下方式简单地设置职位:

  pos = g.new_vertex_property(vector< double>)
pos [g.vertex(0)] =(0,2)
pos [g.vertex(1)] =(0 ,4)
...


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

这篇关于python图形工具中的显式顶点位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆