Line 1: Line 1:
== Dot Graph Examples ==
+
== Running from Command Line ==
  
=== Triangle ===
+
Output to <code>png</code> using <code>twopi</code>
A triangle with large margins
+
  
<pre>
+
dot -Ktwopi -Tpng graph1.gv -o graph1.png
digraph A {
+
  
  rankdir=LR;
+
Other algorithms (Layout Commands)
  center=true; margin=1;
+
* <code>dot</code>
  nodesep=1.5; ranksep=0.5;
+
* <code>fdp</code>
 +
* <code>neato</code>
 +
* <code>osage</code>
 +
* <code>sfdp</code>
 +
* <code>twopi</code>
  
  node [shape=point,  height=".2", width=".2"];
+
Not working on Windows:
 +
* <code>circo</code>
  
  a [xlabel="a"];
+
== Dot Graph Examples ==
  b [xlabel="b"];
+
=== Triangle ===
  c [xlabel="c"];
+
A triangle with large margins
  a -> b -> c;
+
 
  a -> c;
+
digraph A {
}
+
  rankdir=LR;
</pre>
+
  center=true; margin=1;
 +
  nodesep=1.5; ranksep=0.5;
 +
 +
  node [shape=point,  height=".2", width=".2"];
 +
 +
  a [xlabel="a"];
 +
  b [xlabel="b"];
 +
  c [xlabel="c"];
 +
  a -> b -> c;
 +
  a -> c;
 +
}
  
 
http://i.stack.imgur.com/ibImr.png
 
http://i.stack.imgur.com/ibImr.png
Line 25: Line 38:
  
 
=== Label + XLabel ===
 
=== Label + XLabel ===
<pre>
+
digraph A {
digraph A {
+
  rankdir=LR;
 
+
  center=true; margin=1;  
  rankdir=LR;
+
  nodesep=1.5; ranksep=1.5;
  center=true; margin=1;  
+
  nodesep=1.5; ranksep=1.5;
+
  node [height="0.5", width="0.5", fixedsize=true];
 
+
 
  node [height="0.5", width="0.5", fixedsize=true];
+
  X [xlabel=100];
 
+
  Y [xlabel=150];
  X [xlabel=100];
+
  I1 [xlabel=150];
  Y [xlabel=150];
+
  I2 [xlabel=100];
  I1 [xlabel=150];
+
  {X, Y}->{I1, I2};
  I2 [xlabel=100];
+
}
  {X, Y}->{I1, I2};
+
 
+
}
+
</pre>
+
  
 
http://habrastorage.org/files/380/2a0/b41/3802a0b414354ad58397d8a0ebfd0771.png
 
http://habrastorage.org/files/380/2a0/b41/3802a0b414354ad58397d8a0ebfd0771.png
Line 49: Line 58:
 
Source: [http://stackoverflow.com/a/4671684/861423]
 
Source: [http://stackoverflow.com/a/4671684/861423]
  
<pre>
+
digraph A {
digraph A {
+
  rankdir=LR;
  rankdir=LR;
+
  center=true; margin=1;  
  center=true; margin=1;  
+
 
 
+
  node [height="0.33", width="0.33", fixedsize=true];
  node [height="0.33", width="0.33", fixedsize=true];
+
 
 
+
  b->a->d->g;
  b->a->d->g;
+
  a->e->h;
  a->e->h;
+
  e->g;
  e->g;
+
  d->{c,f};
  d->{c,f};
+
 
 
+
  c->e [dir="back"];
  c->e [dir="back"];
+
  g->h [dir="back"];
  g->h [dir="back"];
+
 
 
+
  b,d,e [style=filled, fillcolor=red, peripheries=2];
  b,d,e [style=filled, fillcolor=red, peripheries=2];
+
 
 
+
  {rank=same; f;g;h;}
  {rank=same; f;g;h;}
+
  {rank=same; d;e;c;}
  {rank=same; d;e;c;}
+
  {rank=same; a;b;}
  {rank=same; a;b;}
+
}
}
+
</pre>
+
  
 
http://habrastorage.org/files/ddb/cf5/f66/ddbcf5f668c94490a91a563fcfcd3515.png
 
http://habrastorage.org/files/ddb/cf5/f66/ddbcf5f668c94490a91a563fcfcd3515.png
Line 76: Line 83:
  
 
=== Neato Example ===
 
=== Neato Example ===
<pre>
+
 
graph G {
+
graph G {
  nodesep=1.5;
+
  nodesep=1.5;
  center=true; margin=1;  
+
  center=true; margin=1;  
  node [color=black, shape=rectangle, style="filled", fillcolor=skyblue];
+
  node [color=black, shape=rectangle, style="filled", fillcolor=skyblue];
  edge [len=2];
+
  edge [len=2];
  a;b;c;d;e;
+
  a;b;c;d;e;
  a--{b,c,d,e};
+
  a--{b,c,d,e};
  b--{c,d,e};
+
  b--{c,d,e};
  c--{d,e};
+
  c--{d,e};
  d--e;
+
  d--e;
}
+
}
</pre>
+
  
 
http://habrastorage.org/files/4aa/a61/9d5/4aaa619d5eb6433a812eee3759c82efa.png
 
http://habrastorage.org/files/4aa/a61/9d5/4aaa619d5eb6433a812eee3759c82efa.png
Line 96: Line 102:
 
Source: [http://stackoverflow.com/questions/6219933/how-does-one-define-double-lines-for-edge-and-node-shapes-in-graphviz-dot]
 
Source: [http://stackoverflow.com/questions/6219933/how-does-one-define-double-lines-for-edge-and-node-shapes-in-graphviz-dot]
  
<pre>
+
digraph G {
digraph G {
+
  rankdir=LR;
  rankdir=LR;
+
  nodesep=0.7; ranksep=1;
  nodesep=0.7; ranksep=1;
+
  node [shape=none, fixedsize=true, width=0.3];
  node [shape=none, fixedsize=true, width=0.3];
+
 
 
+
  a->b->d;
  a->b->d;
+
  a->c->d;
  a->c->d;
+
  b->c [color="black:white:black",dir=none];
  b->c [color="black:white:black",dir=none];
+
  a->e->d;
  a->e->d;
+
  c->e [style=invis];
  c->e [style=invis];
+
  {rank=same;b;c;e;}
  {rank=same;b;c;e;}
+
}
}
+
</pre>
+
  
 
http://habrastorage.org/files/f84/5d8/269/f845d826920c4289ae0376767482c798.png
 
http://habrastorage.org/files/f84/5d8/269/f845d826920c4289ae0376767482c798.png

Latest revision as of 23:16, 25 March 2016

Running from Command Line

Output to png using twopi

dot -Ktwopi -Tpng graph1.gv -o graph1.png

Other algorithms (Layout Commands)

  • dot
  • fdp
  • neato
  • osage
  • sfdp
  • twopi

Not working on Windows:

  • circo

Dot Graph Examples

Triangle

A triangle with large margins

digraph A {
  rankdir=LR;
  center=true; margin=1; 
  nodesep=1.5; ranksep=0.5;

  node [shape=point,  height=".2", width=".2"];

  a [xlabel="a"];
  b [xlabel="b"];
  c [xlabel="c"];
  a -> b -> c;
  a -> c;
}

ibImr.png


Label + XLabel

digraph A {
  rankdir=LR;
  center=true; margin=1; 
  nodesep=1.5; ranksep=1.5;

  node [height="0.5", width="0.5", fixedsize=true];
  
  X [xlabel=100];
  Y [xlabel=150];
  I1 [xlabel=150];
  I2 [xlabel=100];
  {X, Y}->{I1, I2};
}

3802a0b414354ad58397d8a0ebfd0771.png


Edges with Opposite Direction

Source: [1]

digraph A {
  rankdir=LR;
  center=true; margin=1; 
  
  node [height="0.33", width="0.33", fixedsize=true];
  
  b->a->d->g;
  a->e->h;
  e->g;
  d->{c,f};
  
  c->e [dir="back"];
  g->h [dir="back"];
  
  b,d,e [style=filled, fillcolor=red, peripheries=2];
  
  {rank=same; f;g;h;}
  {rank=same; d;e;c;}
  {rank=same; a;b;}
}

ddbcf5f668c94490a91a563fcfcd3515.png


Neato Example

graph G {
  nodesep=1.5;
  center=true; margin=1; 
  node [color=black, shape=rectangle, style="filled", fillcolor=skyblue];
  edge [len=2];
  a;b;c;d;e;
  a--{b,c,d,e};
  b--{c,d,e};
  c--{d,e};
  d--e;
}

4aaa619d5eb6433a812eee3759c82efa.png


Double Edge

Source: [2]

digraph G {
  rankdir=LR;
  nodesep=0.7; ranksep=1;
  node [shape=none, fixedsize=true, width=0.3];
  
  a->b->d;
  a->c->d;
  b->c [color="black:white:black",dir=none];
  a->e->d;
  c->e [style=invis];
  {rank=same;b;c;e;}
}

f845d826920c4289ae0376767482c798.png