开发者

How do I add edges between two subgraphs in 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)

I tried:

callgraph.add_edge(pydot.Edge("foo","bar"))

but doesn't work.开发者_Go百科 It just creates two more nodes labeled "foo" and "bar" in the initial graph and puts an edge between them!

Can anyone help, please?


  • Graphviz demands that an edge be between nodes in the 2 clusters.
  • Add graph parameter compound='true'.
  • Use edge parameters lhead= and ltail=.

So your code would become:

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()))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜