我正在尝试从graphviz转换为python。
我认为“虚拟”节点和“虚拟”边缘存在问题。 当我插入g.attr(compound =“ true”)行时,也会出现错误。
Graphviz:
digraph G {
compound=true;
node [shape=box];
edge [dir=none];
subgraph cluster_overall{
subgraph cluster_top{
dummy_top [shape=point width=0 style=invis]
apple;
banana;
}
subgraph cluster_basket{
dummy_basket [shape=point width=0 style=invis]
basket1;
basket2;
label="Baskets";
}
subgraph cluster_bottom{
dummy_bottom [shape=point width=0 style=invis]
orange;
kiwi;
}
label="Test";
}
dummy_top -> dummy_basket [
style=invis
weight=100
lhead="cluster_basket"
ltail="cluster_top"
]
dummy_basket -> dummy_bottom [
style=invis
weight=100
lhead="cluster_bottom"
ltail="cluster_basket"
]
apple -> basket1;
banana -> basket2;
orange -> basket1;
kiwi -> basket2;
}
到目前为止我的python尝试:
g = Digraph('test2', format='png')
g.attr(compound="true")
g.attr('node', shape='record')
g.attr('edge', dir='none')
with g.subgraph(name="cluster_overall") as a:
g.attr(label="test")
# Cluster with bottom top of fruits
with g.subgraph(name='cluster_top') as b:
g.node("dummy_top", shape="point", width="0")
g.node("apple")
g.node("banana")
# Cluster with basket
with g.subgraph(name='cluster_basket') as c:
g.node("dummy_msc", shape="point", width="0")
g.node("basket1")
g.node("basket2")
# Cluster with bottom half of fruits
with g.subgraph(name='cluster_bottom') as d:
g.node("dummy_bottom", shape="point", width="0")
g.node("kiwi")
g.node("orange")
g.edge("dummy_top", "dummy_basket", weight="10", lhead="cluster_msc", ltail="cluster_top")
g.edge("dummy_basket", "dummy_bottom", weight="10", lhead="cluster_bottom", ltail="cluster_basket")
g.edge(apple,basket1)
g.edge(banana,basket2)
g.edge(orange,basket1)
g.edge(kiwi,basket2)
g.view()
图片:
请让我知道我没有正确解释自己。谢谢。