I am trying to plot a graph with 3 levels of nodes, with equal distances between the levels. However, graphviz somehow decides that the distance between the middle level and the bottom one should be much larger than the distance between the top and middle level. Any way to fix this?
Here is my code:
digraph g{ rankdir="LR"; graph [pad="0.5", ranksep="0.525", nodesep="3"]; splines=false; node[shape = square]; edge[style=invis]; subgraph cluster_3 { color=invis; a1->a2->a3->a4->a5->a6->a7; } subgraph cluster_2 { color=invis; a->b->c->d->e->f->g; } subgraph cluster_1 { color=invis; 1->2->3->4->5->6->7; } "a1" [label="1'"]; "a2" [label="2'"]; "a3" [label="3'"]; "a4" [label="4'"]; "a5" [label="5'"]; "a6" [label="6'"]; "a7" [label="7'"]; edge[style=solid, constraint=false]; a->1[arrowhead=none, arrowtail=none]; a->2[arrowhead=none, arrowtail=none]; a->3[arrowhead=none, arrowtail=none]; a->a1[arrowhead=none, arrowtail=none]; a->a2[arrowhead=none, arrowtail=none]; a->a3[arrowhead=none, arrowtail=none]; b->1[arrowhead=none, arrowtail=none]; b->3[arrowhead=none, arrowtail=none]; b->7[arrowhead=none, arrowtail=none]; b->a1[arrowhead=none, arrowtail=none]; b->a3[arrowhead=none, arrowtail=none]; b->a7[arrowhead=none, arrowtail=none]; c->2[arrowhead=none, arrowtail=none]; c->6[arrowhead=none, arrowtail=none]; c->7[arrowhead=none, arrowtail=none]; c->a2[arrowhead=none, arrowtail=none]; c->a6[arrowhead=none, arrowtail=none]; c->a7[arrowhead=none, arrowtail=none]; d->1[arrowhead=none, arrowtail=none]; d->4[arrowhead=none, arrowtail=none]; d->7[arrowhead=none, arrowtail=none]; d->a1[arrowhead=none, arrowtail=none]; d->a4[arrowhead=none, arrowtail=none]; d->a7[arrowhead=none, arrowtail=none]; e->1[arrowhead=none, arrowtail=none]; e->2[arrowhead=none, arrowtail=none]; e->3[arrowhead=none, arrowtail=none]; e->a1[arrowhead=none, arrowtail=none]; e->a2[arrowhead=none, arrowtail=none]; e->a3[arrowhead=none, arrowtail=none]; f->1[arrowhead=none, arrowtail=none]; f->4[arrowhead=none, arrowtail=none]; f->7[arrowhead=none, arrowtail=none]; f->a1[arrowhead=none, arrowtail=none]; f->a4[arrowhead=none, arrowtail=none]; f->a7[arrowhead=none, arrowtail=none]; g->5[arrowhead=none, arrowtail=none]; g->6[arrowhead=none, arrowtail=none]; g->7[arrowhead=none, arrowtail=none]; g->a5[arrowhead=none, arrowtail=none]; g->a6[arrowhead=none, arrowtail=none]; g->a7[arrowhead=none, arrowtail=none]; }
The output looks like this currently:
neato is a reasonable default tool to use for undirected graphs that aren't too large (about 100 nodes), when you don't know anything else about the graph. neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.
Ranks and Subgraphs To work out the layout, Graphviz uses a system it calls "ranks". Each node is assigned a higher rank than the highest ranked node that point to it. If your rank direction is set to left to right ( rankdir=LR ), then nodes with a higher rank are placed further to the right.
Abstract grammar for defining Graphviz nodes, edges, graphs, subgraphs, and clusters. Terminals are shown in bold font and nonterminals in italics. Literal characters are given in single quotes.
Create a graph object, assemble the graph by adding nodes and edges, and retrieve its DOT source code string. Save the source code to a file and render it with the Graphviz installation of your system. Use the view option/method to directly inspect the resulting (PDF, PNG, SVG, etc.) file with its default application.
Just played around a bit and came up with the below graph, is this any closer to want to want?
digraph g{ graph [pad="0.5", nodesep="1", ranksep="2"]; splines="false"; node[shape = square]; edge[style=invis]; a1->a->1 a2->b->2 a3->c->3 a4->d->4 a5->e->5 a6->f->6 a7->g->7 "a1" [label="1'"]; "a2" [label="2'"]; "a3" [label="3'"]; "a4" [label="4'"]; "a5" [label="5'"]; "a6" [label="6'"]; "a7" [label="7'"]; edge[style=solid, constraint=false]; a->1[arrowhead=none, arrowtail=none]; a->2[arrowhead=none, arrowtail=none]; a->3[arrowhead=none, arrowtail=none]; a->a1[arrowhead=none, arrowtail=none]; a->a2[arrowhead=none, arrowtail=none]; a->a3[arrowhead=none, arrowtail=none]; b->1[arrowhead=none, arrowtail=none]; b->3[arrowhead=none, arrowtail=none]; b->7[arrowhead=none, arrowtail=none]; b->a1[arrowhead=none, arrowtail=none]; b->a3[arrowhead=none, arrowtail=none]; b->a7[arrowhead=none, arrowtail=none]; c->2[arrowhead=none, arrowtail=none]; c->6[arrowhead=none, arrowtail=none]; c->7[arrowhead=none, arrowtail=none]; c->a2[arrowhead=none, arrowtail=none]; c->a6[arrowhead=none, arrowtail=none]; c->a7[arrowhead=none, arrowtail=none]; d->1[arrowhead=none, arrowtail=none]; d->4[arrowhead=none, arrowtail=none]; d->7[arrowhead=none, arrowtail=none]; d->a1[arrowhead=none, arrowtail=none]; d->a4[arrowhead=none, arrowtail=none]; d->a7[arrowhead=none, arrowtail=none]; e->1[arrowhead=none, arrowtail=none]; e->2[arrowhead=none, arrowtail=none]; e->3[arrowhead=none, arrowtail=none]; e->a1[arrowhead=none, arrowtail=none]; e->a2[arrowhead=none, arrowtail=none]; e->a3[arrowhead=none, arrowtail=none]; f->1[arrowhead=none, arrowtail=none]; f->4[arrowhead=none, arrowtail=none]; f->7[arrowhead=none, arrowtail=none]; f->a1[arrowhead=none, arrowtail=none]; f->a4[arrowhead=none, arrowtail=none]; f->a7[arrowhead=none, arrowtail=none]; g->5[arrowhead=none, arrowtail=none]; g->6[arrowhead=none, arrowtail=none]; g->7[arrowhead=none, arrowtail=none]; g->a5[arrowhead=none, arrowtail=none]; g->a6[arrowhead=none, arrowtail=none]; g->a7[arrowhead=none, arrowtail=none]; }
To add to @uncletall answer (and partially address @ingomueller.net question), it looks like the nodesep and ranksep have big factors in how the nodes will be separated:
http://www.graphviz.org/doc/info/attrs.html#d:nodesep
nodesep : double, default: 0.25, minimum: 0.02 In dot, nodesep specifies the minimum space between two adjacent nodes in the same rank, in inches.
For other layouts, nodesep affects the spacing between loops on a single node, or multiedges between a pair of nodes.
Valid for: Graphs.
http://martin-loetzsch.de/S-DOT/ranksep.html
The gives desired rank separation, in inches. This is the minimum vertical distance between the bottom of the nodes in one rank and the tops of nodes in the next.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With