python - Graph_Tool - 使用用户定义的顶点文本绘制图形

标签 python graph-tool

我试图在不同的顶点设置文本并绘制​​它们,但我不知道如何制作。 我搜索了 graph_tool documentaction 但我找不到如何制作它,因为那里的例子太困惑了......

我的代码是:

from graph_tool.all import *
g = Graph()
g.add_vertex()
// How to something like: g.vertex(0).text = "A"
g.add_vertex()
// How to something like: g.vertex(1).text = "B"
g.add_edge(g.vertex(0),g.vertex(1))
// And how to use it instead of vertex_index
graph_draw(g, vertex_text=g.vertex_index, vertex_font_size=18, output_size=(200, 200), output="test.png")

等待线索

最佳答案

#!/usr/bin/python3

from graph_tool.all import *

g = Graph()

v1 = g.add_vertex()
v2 = g.add_vertex()

e = g.add_edge(v1, v2)

v_prop = g.new_vertex_property("string")
v_prop[v1] = 'foo'
v_prop[v2] = 'bar'

e_prop = g.new_edge_property("string")
e_prop[e] = 'e1'

graph_draw(g, vertex_text=v_prop,edge_text=e_prop, vertex_font_size=18, output_size=(200, 200), output="two-nodes.png")

这真的应该在图形工具网站介绍上。

如果您能了解如何设置边长,我很想知道。

#!/usr/bin/python3

from graph_tool.all import *

g = Graph()

v1 = g.add_vertex()
v2 = g.add_vertex()
v3 = g.add_vertex()

e2 = g.add_edge(v1, v2)
e1 = g.add_edge(v1, v3)

v_prop = g.new_vertex_property("string")
v_prop[v1] = 'foo'
v_prop[v2] = 'bar'
v_prop[v3] = 'baz'

e_prop = g.new_edge_property("string")
e_prop[e1] = 'edge 1'
e_prop[e2] = 'edge 2'

e_len = g.new_edge_property("double")
e_len[e1] = 10
e_len[e2] = 20

graph_draw(g, vertex_text=v_prop, edge_text=e_prop, edge_pen_width = e_len, vertex_font_size=18, output_size=(800, 800), output="two-nodes.png")

这就是我正在使用的,因为我可以操纵宽度...如果我尝试设置长度,它会提示。

关于python - Graph_Tool - 使用用户定义的顶点文本绘制图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221792/

相关文章:

python - 从字典创建图形工具图形

带有图形数据库的 python 图形工具库

python - 添加 Pandas 系列列表

python - 有没有简单的方法可以在Python类构造函数中指定参数的默认值而不需要编写继承?

Python Pandas 矩阵乘法 多项运算合二为一

python - 使用图形工具绘制时阻止顶点相互重叠

python - Graph-tool中的基本用法 : how to delete vertex and related edges in the Graph-tool?

python - 使用 "ws.cell(row = row, column = columnl).value = looprow"删除之前保存在 python 中的数据

python - 使用 GtkBuilder 自动连接信号时对话框中断,但在手动连接信号时有效

graph-tool - 在图形工具中查找源和目标之间的所有路径,返回边而不是顶点