Reducing the size (as in area) of the graph generated by graphviz
In my experience using graphviz to render graphs of that size (~ 700 nodes), minimal trial-and-error adjustment to this combination of attribute settings--some structural, some purely aesthetic--for all three objects (graph, nodes, and edges) should do what you want:
reduce the minimum separation between nodes, via 'nodesep'; e.g., nodes[nodesep=0.75]; this will make your graph being "too compact." (nodesep and ranksep probably affect how dot draws a graph more than any other adjustable parameter)
reduce the minimum distance between nodes of different ranks, e.g, nodes[ranksep=0.75]; 'ranksep' sets the minimum distance between nodes of different ranks--this will affect your graph layout significantly if your graph is comprised of many ranks
increase the edge weights, eg, edge[weight=1.2]; this will make the edges shorter, in turn making the entire graph more compact
remove node borders and node fill, e.g., nodes[color=none; shape=plaintext], especially for oval-shaped nodes, a substantial fraction of the total node space is 'unused' (ie, not used to display the node label); each node's footprint is now reduced to just its text
explicitly set the font size for the nodes (the node borders are enlarged so that they surround the node text, which means that the font size and amount of text for a given node has a significant effect on its size); [fontsize=11] should be large enough to be legible yet also reduce the 'cluttered' appearance (the default size is 14)
use different colors for nodes and edges--this will make your graph easier to read; e.g., set the node 'text' fontcolor to blue and the edge fontcolor to "grey" to help the eye distinguish the two sets of graph structures. This will make a bigger difference than you might think.
explicitly set total graph size, eg, graph[size="7.75,10.25"] (ensures that your graph fits on an 8.5 x 11 page and that it occupies the entire space)
meteoritepanama
Updated on June 27, 2020Comments
-
meteoritepanama almost 4 years
Does anyone have any general tips for reducing the size of a graph generated by graphviz (size as in area, not as in file size).
I have a fairly large graph (700 nodes). I set a smaller font size for each node, but it seems to only reduce the font size and not the actual node size. Are there any attributes to reduce the overall amount of blank space in the graph also? Thanks!
-
meteoritepanama almost 14 yearsThanks for the detailed response. The only problem I have is that setting the font size doesn't seem to reduce the overall node size for it. It seems like the only thing that gets smaller is the font.
-
Deepak Mathpal almost 14 yearsno problem. Regarding 'fontsize', if you removed the node borders and node fill first, so that the representation of each node is just the node text, then reducing the text size is exactly what you want, because it reduces the 'apparent' node size. (Granted, removing the node borders/fill doesn't always improve overall 'resolution'--just depends on your graph, but you'll know as soon as you try it).
-
Forbesmyester about 11 yearsThe suggestions above are great and provide much more power than what I do...
cat [something.dot] | dot-Gdpi=64 -Tpng:cairo:cairo > [outfile.png]
which just scales the graph... -
lightalchemist almost 11 yearsChanging the node edge to grey really made a difference especially when you have to pore over huge messy graphs. Thanks!
-
Suzanne Soy over 8 years
nodes[nodesep=0.75]
doesn't work anymore, it has to be put directly into the graph. Same forranksep
-
einpoklum almost 8 years@GeorgesDupéron: Can you give an example? Alternatively, and maybe even better, can you make an edit to the answer?