Search code examples
graphvizdot

Creating a more compact layout in GraphViz using dot


I have a directed graph on 31 nodes for which Graphviz' dot layout engine produces the following layout:

enter image description here

I'm unhappy with the layout because there is too much space surrounding the four-node-cluster 8-10-20-21. What settings can I tweak to improve Graphviz' layout of graphs like these? Interestingly, if I change the direction of the 25-21 edge I get a much more compact layout:

enter image description here

I guess this is because Graphviz strongly believes that all edges should point downwards. Perhaps I tell Graphviz that it is ok for some edges to point upwards?

You can play with the graph here.


Solution

  • You can annotate the offending edge as "21" -> "25" [dir = "back"]; to keep the original arrow while changing the sense of the hierarchy implicit in the dot layout.

    using constraint = false can help in some circumstances, but it often results in the layout of the edge to be routed in an unexpected (read ugly) path.