Graphviz:边到记录标签 Python (gv)
Graphviz: edge to record label in Python (gv)
我很难生成以下边缘:
...
h1 -> "h2":f2;
如本例所示:datastruct
考虑以下 Python 代码:
#!/usr/bin/env python
import sys
import gv
gh = gv.digraph('g')
gv.setv(gh, 'rankdir', "LR")
node = gv.protonode(gh)
gv.setv(node, 'shape', 'record')
n1 = gv.node(gh, "h1")
n2 = gv.node(gh, "h2")
gv.setv(n2, "label", "<f1> s1 | <f2> s2")
e = gv.edge(n1, n2)
gv.write(gh, "out.dot")
执行后输出如下:
digraph g {
node [label="\N"];
graph [rankdir=LR];
h1 [shape=record];
h2 [label="<f1> s1 | <f2> s2", shape=record];
h1 -> h2;
}
这让我产生了一个问题,即如何获得上面显示的边缘以使其指向正确的记录条目。
提前致谢。
您需要设置 headport 才能做到这一点:
我只用 C 语言做过这个,但是根据你在 python 中展示的内容,我认为是这样的:
e = gv.edge(n1, n2)
gv.setv(e, "headport", "f1") # or another key from the records
这将创建这样的边缘:
h1 -> h2:f1;
如果需要指向反方向也可以设置尾口
我很难生成以下边缘:
...
h1 -> "h2":f2;
如本例所示:datastruct
考虑以下 Python 代码:
#!/usr/bin/env python
import sys
import gv
gh = gv.digraph('g')
gv.setv(gh, 'rankdir', "LR")
node = gv.protonode(gh)
gv.setv(node, 'shape', 'record')
n1 = gv.node(gh, "h1")
n2 = gv.node(gh, "h2")
gv.setv(n2, "label", "<f1> s1 | <f2> s2")
e = gv.edge(n1, n2)
gv.write(gh, "out.dot")
执行后输出如下:
digraph g {
node [label="\N"];
graph [rankdir=LR];
h1 [shape=record];
h2 [label="<f1> s1 | <f2> s2", shape=record];
h1 -> h2;
}
这让我产生了一个问题,即如何获得上面显示的边缘以使其指向正确的记录条目。
提前致谢。
您需要设置 headport 才能做到这一点:
我只用 C 语言做过这个,但是根据你在 python 中展示的内容,我认为是这样的:
e = gv.edge(n1, n2)
gv.setv(e, "headport", "f1") # or another key from the records
这将创建这样的边缘:
h1 -> h2:f1;
如果需要指向反方向也可以设置尾口