官方网站:http://www.graphviz.org/
Graphviz (Graph Visualization Software) 是一个由AT&T实验室启动的开源工具包。DOT是一种图形描述语言,非常简单的,
Graphviz就是用来处理这种语言的工具。只需要简单了解一下DOT语言,就可以用Graphviz绘图了,它对程序员特别有用。
安装
sudo apt -y install graphviz
安装了命令包
使用
无向图
graph graphname { a -- b -- c; b -- d; }
运行命令:
dot test.dot -Tpng -o test.png
在当前目录下生成test.png文件
有向图
digraph graphname { a -> b -> c; b -> d; }
设置权重
digraph tr{ a -> b [label="20"]; b -> c [label="30"]; }
二叉树
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://www.cnblogs.com/zuofaqi/p/9861249.html