S.Gu
S.Gu

Reputation: 649

Graphviz Decision tree display separately for the same elements

I have the codes here,

import graphviz as gv
d=gv.Digraph()
d.edge('a','b')
d.edge('a','c')
d.edge('b','c')

the output is as pic:

enter image description here

How can I get a graph like this:

enter image description here

Upvotes: 0

Views: 55

Answers (1)

vaettchen
vaettchen

Reputation: 7659

Not using Python, I only have a pure graphviz answer but you should be able to translate that easily into Python.

You need to do two things:

  • Create four nodes, not three, and give them the label you want
  • Put the nodes you want to have on the same level into a rank = same instruction (not strictly necessary in the example context but may be needed for more complex graphs)

Here we go:

digraph so 
{
    n_1[ label = "a" ];
    n_2[ label = "b" ];
    n_3[ label = "c" ];
    n_4[ label = "c" ];

    { rank = same; n_2 n_3 }

    n_1 -> { n_2 n_3 };
    n_2 -> n_4;
}

which gives you

enter image description here

Upvotes: 1

Related Questions