Change Size (Width and Height) of Graph (GraphViz & dot)
Asked Answered
E

2

14

Often, the default layout of graphs drawn by GraphViz in the dot language is a little "tight." With too little visual space, it's hard to put meaningful labels on edges and the graph can look cluttered.

How do I affect the vertical and horizontal spacing of GraphViz / dot graphs?

Encaustic answered 24/6, 2017 at 10:6 Comment(0)
E
25

DEFAULT

I will start with a simple graph that is laid out by the dot engine in the default manner:

digraph {
node [shape=circle, width=0.4];
A->B
A->D
B->C
D->E 
}

enter image description here

CHANGING HEIGHT

As you can see, the layout is quite tight. Notice that my ranks (rows) naturally go from top to bottom. I can affect the height of the graph by exploiting this and using the ranksep (rank separation) variable to explicitly set the space between the ranks:

digraph { 
node [shape=circle, width=0.4];
ranksep = 1;
A->B
A->D
B->C
D->E 
}

enter image description here

CHANGING WIDTH

Finally, we may want to widen the diagram. Here we use the nodesep variable to increase the space between the nodes (columns):

digraph { 
node [shape=circle, width=0.4];
nodesep=1.5;
A->B
A->D
B->C
D->E 
}

enter image description here

Encaustic answered 24/6, 2017 at 10:6 Comment(3)
Is there any official documentation available? Thanks.Adamski
@Adamski Of course, it's at graphviz.org It's much-changed since I answered this question four years ago, but looks better now.Encaustic
If you're using dot command to visualize a generated digraph, you can add these as options to the command: -Granksep=1 or -Gnodesep=1.5 etc.Wesleywesleyan
A
0

you can use ratio argument as well as specify within the documentation https://graphviz.org/doc/info/attrs.html

Agnate answered 16/2, 2023 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.