转载自 http://blog.csdn.net/zhangskd/article/details/8250470
概述
官网:http://www.graphviz.org/
Graphviz (Graph Visualization Software) 是一个由AT&T实验室启动的开源工具包。DOT是一种图形描述语言,非常简单的,
Graphviz就是用来处理这种语言的工具。只需要简单了解一下DOT语言,就可以用Graphviz绘图了,它对程序员特别有用。
So in short, if you are a programmer, it is born for you。
无向图
- graph graphname {
- a -- b -- c;
- b -- d;
- }
![](https://img-my.csdn.net/uploads/201212/03/1354527473_9115.png)
有向图
- digraph graphname {
- a -> b -> c;
- b -> d;
- }
![](https://img-my.csdn.net/uploads/201212/03/1354527753_2395.png)
属性
-
-
- digraph graphname {
-
- a [lable = "Foo"];
-
-
- b [shape = box];
-
-
- a -> b -> c [color = blue];
-
-
- b -> d [style = dotted];
- }
基本图形
- digraph G {
-
- size = "4,4";
- main [shape = box];
-
-
- main->parse [weight = 8];
- parse->execute;
-
-
- main->init[style = dotted];
- main->cleanup;
-
-
- execute->{make_string;printf}
- init->make_string;
-
-
- edge [color = red];
- main->printf [sytle=bold, label = "100times"];
-
-
- make_string [label = "make a\nstring"];
-
-
- node [shape=box,style =filled,color=lightgrey];
- execute->compare;
- }
![](https://img-my.csdn.net/uploads/201212/03/1354529501_4261.png)
多边形
- digraph G{
- a -> b -> c;
- b -> d;
-
-
- a [shape = polygon, sides = 5, peripheries = 3, color = lightblue, style = filled];
-
-
- c [shape = polygon, sides = 4, skew = 0.4, label = "hello world"];
-
-
- d [shape = invtriangle,orientation = 30];
-
-
- e [shape = polygon, sides = 4, distortion = 0.7];
- }
![](https://img-my.csdn.net/uploads/201212/03/1354528026_1405.png)
数据结构
(1)复杂的标签
- digraph structs {
-
- node [shape = record];
-
- struct1 [label = "left|middle|right"];
- struct2 [label = "one|two"];
- struct3 [label = "hello\nworld|{b|{c|d|e}|f}|g|h"];
-
- struct1 -> struct2;
- struct1 -> struct3;
- }
![](https://img-my.csdn.net/uploads/201212/03/1354528144_9002.png)
- graph picture {
-
- label = "I love you";
-
-
- labelloc = b;
-
-
- labeljust = l;
-
- edge[decorate = true];
-
- C -- D [label = "s1"];
- C -- E [label = "s2"];
- C -- F [label = "s3"];
- D -- E [label = "s4"];
- D -- F [label = "s5"];
-
- edge[decorate = false, labelfontcolor = blue, fontcolor = red];
- C1 -- D1 [headlabel = "c1",taillabel = "d1",label = "c1 - d1"];
- }
(2)行列对齐
- digraph html {
- rankdir = LR;
- {
- node[shape = plaintext];
- 1995 -> 1996 -> 1997 -> 1998 -> 1999 -> 2000 -> 2001;
- }
- {
- node[shape = box, style = filled];
- WAR3 -> Xhero -> Footman -> DOTA:
- WAR3 -> Battleship;
- }
- {rank = same; 1996; WAR3;}
- {rank = same; 1998; Xhero; Battleship;}
- {rank = same; 1999; Footman;}
- {rank = same; 2001; DOTA;}
- }
![](https://img-my.csdn.net/uploads/201212/03/1354528314_2222.png)
(3)二叉树
- digraph G {
- label = "Binary search tree";
- node [shape = record];
-
- A [label = "<f0>|<f1>A|<f2>"];
- B [label = "<f0>|<f1>B|<f2>"];
- C [label = "<f0>|<f1>C|<f2>"];
- D [label = "<f0>|<f1>D|<f2>"];
- E [label = "<f0>|<f1>E|<f2>"];
- F [label = "<f0>|<f1>F|<f2>"];
- G [label = "<f0>|<f1>G|<f2>"];
-
- A:f0 -> B:f1;
- A:f2 -> C:f1;
- B:f0 -> D:f1;
- B:f2 -> E:f1;
- C:f0 -> F:f1;
- C:f2 -> G:f1;
- }
![](https://img-my.csdn.net/uploads/201212/03/1354528355_9701.png)
(4)哈希表
- digraph G{
- nodesep = .05;
- rankdir = LR;
-
- node [shape = record,width = .1,height = .1];
- node0 [label = "<f0>|<f1>|<f2>|<f3>|<f4>|<f5>|<f6>|",height = 2.5];
-
- node [width = 1.5];
- node1 [label = "{<n>n14|719|<p>}"];
- node2 [label = "{<n>a1|805|<p>}"];
- node3 [label = "{<n>i9|718|<p>}"];
- node4 [label = "{<n>e5|989|<p>}"];
- node5 [label = "{<n>t20|959|<p>}"];
- node6 [label = "{<n>o15|794|<p>}"];
- node7 [label = "{<n>s19|659|<p>}"];
-
- node0:f0 -> node1:n;
- node0:f1 -> node2:n;
- node0:f2 -> node3:n;
- node0:f5 -> node4:n;
- node0:f6 -> node5:n;
- node2:p -> node6:n;
- node4:p -> node7:n;
- }
![](https://img-my.csdn.net/uploads/201212/03/1354528430_5081.png)
流程图
- digraph G{
- subgraph cluster0 {
- node [style = filled,color = white];
- style = filled;
- color = lightgrey;
- a0 -> a1 -> a2 -> a3;
- label = "process #1";
- }
-
- subgraph cluster1 {
- node [style = filled];
- b0 -> b1 -> b2 -> b3;
- label = "process #2";
- color = blue;
- }
-
- start -> a0;
- start -> b0;
- a1 -> b3;
- b2 -> a3;
- a3 -> a0;
- a3 -> end;
- b3 -> end;
- start [shape = Mdiamond];
- end [shape = Msquare];
- }
![](https://img-my.csdn.net/uploads/201212/03/1354528519_8284.png)
Reference
[1] http://zh.wikipedia.org/zh-cn/DOT语言,DOT语言简明介绍。
[2] http://zh.wikipedia.org/zh/Graphviz,简单背景知识。
[3] Graphviz中文指南。