Merge two dot graphs at a common node in python

回眸只為那壹抹淺笑 提交于 2019-12-04 19:36:33

The way to merge the two graphs would be defining a single digraph having two subgraphs.

from graphviz import Source

clusters = """
digraph G{

subgraph cluster0 {
    edge [dir=forward]
    node [shape=plaintext]

    0 [label="0 (None)"]
    0 -> 5 [label="root"]
    1 [label="1 (John)"]
    2 [label="2 (is)"]
    3 [label="3 (a)"]
    4 [label="4 (computer)"]
    5 [label="5 (scientist)"]
    5 -> 2 [label="cop"]
    5 -> 4 [label="compound"]
    5 -> 3 [label="det"]
    5 -> 1 [label="nsubj"]
}

subgraph cluster1 {
edge [dir=forward]
node [shape=plaintext]

0 [label="0 (None)"]
0 -> 2 [label="root"]
1 [label="1 (John)"]
2 [label="2 (has)"]
2 -> 5 [label="dobj"]
2 -> 1 [label="nsubj"]
3 [label="3 (an)"]
4 [label="4 (elder)"]
5 [label="5 (sister)"]
5 -> 6 [label="acl"]
5 -> 3 [label="det"]
5 -> 4 [label="amod"]
6 [label="6 (named)"]
6 -> 7 [label="dobj"]
7 [label="7 (Mary)"]
}
}
"""



src = Source(clusters, format='png')
src.render("graphing1", view=True)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!