I generate a pydot graph with the following code
graph1 = pydot.Dot(graph_type='digraph')
A = pydot.Node("A", style="filled", fillcolor="green")
B = pydot.Node("B", style="filled", fillcolor="blue")
graph1.add_node(A)
graph1.add_node(B)
graph1.add_edge(pydot.Edge(A,B))
graph1.write_png('graph1.png')
and my output is
and I generate a another pydot graph with the following code
graph2 = pydot.Dot(graph_type='digraph')
C = pydot.Node("C", style="filled", fillcolor="green")
D = pydot.Node("D", style="filled", fillcolor="blue")
graph2.add_node(C)
graph2.add_node(D)
graph2.add_edge(pydot.Edge(C,D))
graph2.write_png('graph2.png')
and my output is as follows.
My request is how to merge these 2 graphs(graph1 and graph2)? My expected output after merging as
I tried with the following code, but, its not working..
graph3 = pydot.Dot(graph_type='digraph')
graph1_leaf = pydot.Node(graph1.get_node(B), style="filled",
fillcolor="green")
graph2_root = pydot.Node(graph2.get_node(C), style="filled",
fillcolor="green")
graph3.add_node(graph1_leaf)
graph3.add_node(graph2_root)
graph3.add_edge(pydot.Edge(graph1_leaf,graph2_root))
graph3.write_png('graph3.png')
Please guide me to merge these 2 graphs using pydot in python.. Thanks in advance..