I am creating some graphs (random edges on each run) with the help of a python library, however I get some graphs with a layout I do not want.
I need a three layered graph, the green triangles in the top row, the orange ellipses in the middle and the blue rectangles on the bottom row.
However, sometimes there are some orange ones in the bottom row, and I can not understand why this is happening or how I can prevent this.
There’s some option to put nodes on the highest possible level (at least if there is slack in the assignment) if someone can find it or if it was ever documented
[fyi, layers means something else to Graphviz (FAQ | Graphviz), but we’ll ignore that]
Dot tries to minimize the number of ranks in a graph. While rank=same forces a set of nodes to appear on the same rank, it does not prevent dot from placing other nodes on that same rank. You created a set of nodes, but not an exclusive set of nodes.
Since you are setting the top and bottom “layers” to be single ranks, all you need to do is set the top layer to rank=source and the bottom layer to rank=sink (rank | Graphviz) This will make the sets exclusive.
Like so: