如何在pydot中的两个子图之间添加边? [英] How do I add edges between two subgraphs in pydot?
本文介绍了如何在pydot中的两个子图之间添加边?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在pydot的两个子图(簇)之间添加边吗?
Does anyone know how to add an edge between two subgraphs (clusters) in pydot?
callgraph = pydot.Dot(graph_type='digraph',fontname="Verdana")
cluster_foo=pydot.Cluster('foo',label='foo')
cluster_foo.add_node(pydot.Node('foo_method_1',label='method_1'))
callgraph.add_subgraph(cluster_foo)
cluster_bar=pydot.Cluster('bar',label='Component1')
cluster_bar.add_node(pydot.Node('bar_method_a'))
callgraph.add_subgraph(cluster_bar)
我尝试过:
callgraph.add_edge(pydot.Edge("foo","bar"))
但不起作用.它只是在初始图中再创建两个标记为"foo"和"bar"的节点,并在它们之间放置一条边!
but doesn't work. It just creates two more nodes labeled "foo" and "bar" in the initial graph and puts an edge between them!
任何人都可以帮忙吗?
推荐答案
- Graphviz要求边缘在2个簇中的 nodes 之间.
- 添加图形参数compound ='true'.
- 使用边缘参数lhead =和ltail =.
- Graphviz demands that an edge be between nodes in the 2 clusters.
- Add graph parameter compound='true'.
- Use edge parameters lhead= and ltail=.
因此您的代码将变为:
callgraph = pydot.Dot(graph_type='digraph', fontname="Verdana", compound='true')
cluster_foo=pydot.Cluster('foo',label='foo')
callgraph.add_subgraph(cluster_foo)
node_foo = pydot.Node('foo_method_1',label='method_1')
cluster_foo.add_node(node_foo)
cluster_bar=pydot.Cluster('bar',label='Component1')
callgraph.add_subgraph(cluster_bar)
node_bar = pydot.Node('bar_method_a')
cluster_bar.add_node(node_bar)
callgraph.add_edge(pydot.Edge(node_foo, node_bar, ltail=cluster_foo.get_name(), lhead=cluster_bar.get_name()))
这篇关于如何在pydot中的两个子图之间添加边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文