基础例子

简单示例

graph simple {
  a -- b;
  b -- d;
  b -- c;
  d -- a;
}
使用下面的命令转换为图片
dot -Tpng -o simple.png simple.dot
simple

调整布局

graph different_layout {
  rankdir = LR; (1)
  a -- b;
  b -- c;
  b -- d;
  d -- a;
}
1 排列方向自左向右(Rank direction Left to Right)
diffenent_layout

简单有向图

digraph simple_digraph {
  a -> b;
  b -> c;
  a -> c;
}
digraph

带标签的简单有向图

digraph digraph_with_label {
  T[label="Teacher"]
  P[label="Pupil"]
  T -> P [label="Instrutions", fontcolor=darkgreen]
}
digraph_with_label

修改形状和颜色

digraph attribute {
  T[label="Teacher" color=Blue, fontcolor=Red, fontsize=24, shape=circle]
  P[label="Pupil" color=Red, fontcolor=Black, fontsize=18, shape=box]
  T -> P [label="Instrutions", fontcolor=darkgreen]
}
attribute
这里可供选择的形状有box、polygon、ellipse、oval、circle、point、egg、triangle、plaintext、diamond、trapezium、parallelogram、house、pentagon、hexagon、septagon、octagon、doublecircle、doubleoctagon、tripleoctagon更多形状请参考 这里

小结

digraph summery {
  start [label="Start with a Node"]
  next [label="Choose your shape", shape=box]
  warning [label="Don't go overboard", color=Blue, fontcolor=Red, fontsize=24,style=filled, fillcolor=green, shape=octagon]
  end [label="Darw  your graph!", shape=box, style=filled, fillcolor=yellow]

  start -> next
  start -> warning
  next -> end [label="Getting batter...", fontcolor=darkblue]
}
summery

高级

节约时间的技巧

digraph hierachy {
  nodesep = 1.0 // increases the separation between nodes

  node [color=Red, fontname=Courier, shape=box] // All nodes will this shape and colour

  edge [color=Blue, style=dashed] // All the lines look like this

  Headteacher -> {Deputy1 Deputy2 BusinessManager}
  Deputy1 -> {Teacher1 Teacher2}
  BusinessManager->ITManager
  {rank=same;ITManager Teacher1 Teacher2} // Put them on the same level
}
hierarchy

记录

digraph structs {
  node [shape=record]
  struct1 [label="<f0> left|<f1> mid\ dle|<f2> right"];
  struct2 [label="{<f0> one| two \n\n\n}" shape=Mrecord];
  struct3 [label="hello\nworld | {b | {c | <here> d | e } | f } | g | h"];

  struct1:f1 -> struct2:f0;
  struct1:f0 -> struct3:f1;
}
structs

例子

有限状态机

digraph finite_state_machine {
  rankdir=LR;
  size = "8.5"
  node [shape = circle];
  S0 -> S1 [label="Lift Nozzle"]
  S1 -> S0 [label="Replace Nozzle"]
  S1 -> S2 [label="Authorize Pump"]
  S2 -> S0 [label="Replace Nozzle"]
  S2 -> S3 [label="Pull Tirgger"]
  S3 -> S2 [label="Release Tigger"]
}
finite_state_machine

数据流示意图

digraph dfd {
  node[shape=record]
  store[label="<f0> left | <f1> Some data store"]
  proc1[label="{<f0> 1.0 | <f1> Some process here\n\n\n}" shape=Mrecord];
  enti1[label="Customer" shape=box];
  store:f1 -> proc1:f0;
  enti1 -> proc1:f0;
}
dfd
digraph dfd2 {
  node[shape=record]
  subgraph level0 {
    enti1[label="Customer" shape=box];
    enti2[label="Manager" shape=box];
  }

  subgraph cluster_level1 {
    label = "Level 1";
    proc1 [label="{<f0> 1.0 | <f1> One process here\n\n\n}" shape=Mrecord];
    proc2 [label="{<f0> 2.0 | <f1> Other process here\n\n\n}" shape=Mrecord];
    store1 [label="<f0> | <f1> Data store one"];
    store2 [label="<f0> | <f1> Data store two"];
    {rank=same; store1, store2}
  }

  enti1 -> proc1
  enti2 -> proc2
  store1 -> proc1
  store2 -> proc2
  proc1 -> store2
  store2 -> proc1
}
dfd2

对象继承

digraph obj {
  node[shape=record];
  rankdir
}