【问题标题】:Explicit vertex position in python graph-toolpython图形工具中的显式顶点位置
【发布时间】:2014-04-25 17:06:49
【问题描述】:

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

有一个代码 sn-p 可能会对您有所帮助。

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

如果我要在 (0,2), (0,4) ... (0,8) 处定义我的顶点位置,我该怎么办?

在上面的代码 sn-p 中,我可以将 dim 更改为 2。但我不想要随机布局。

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

【问题讨论】:

    标签: python graph draw dot graph-tool


    【解决方案1】:

    你可以简单地设置位置如下:

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

    【讨论】:

    • 运行第二行时出现错误,ValueError: Invalid vertex index: 0
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多