2
votes

I am trying to get a graph looking similar to this with Graphviz:

enter image description here

But using this code:

from graphviz import Digraph
G = Digraph()

G.node_attr = {
    "shape": "rectangle",
    "width": "2",
    "height": "2"
}

G.node("A")
G.node("B")
x = "0.5"
G.node("B1", width=x, height=x)
G.node("B2", width=x, height=x)
G.node("B3", width=x, height=x)
G.node("C")

G.edge("A", "B")
G.edge("B", "C")
G.edge("A", "B1")
G.edge("B1", "B2")
G.edge("B1", "B3")

I end up with this:

enter image description here

I want B1, B2 and B3 to be in the same "vertical level" as B. I am sure this can be achieved with subgraphs, but I cannot figure out how to do it.

1
I deleted my answer as I completely misread your question. I don't think there is an easy solution for this with graphviz. - marapet

1 Answers

0
votes

Just found a mostly sufficient workaround by introducing an additional invisible edge and adjusting the node separation.

By simply adding the two lines

G.edge("B2", "C", style="invis")
G.attr(nodesep="1")

at the end of the code in the original post, one gets the result: enter image description here