tags:

views:

43

answers:

1

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!

+1  A: 

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, edges[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)

doug
Thanks 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.
garsh0p
no 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).
doug