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 does not work. It just creates two more nodes labeled "foo" and "bar" in the initial graph, as well as between them and the border!

Can anyone help please?

Thanks!

+4
source share
1 answer
  • Graphviz requires the edge to be between nodes in 2 clusters.
  • Add graph parameter parameter = 'true'.
  • Use edge options lhead = and ltail =.

Thus, your code will be as follows:

 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())) 
+5
source

All Articles