1)运行命令:
dot -Tpng 目录\example.dot -o 目录\example.png
2)基本概念
- 有向图 (Digraph):它的边有一个明确的起点和终点。
- 无向图 (Graph):它的边没有明确的起点和终点。
digraph G { ... } // 有向图
graph G { ... } // 无向图
1. 节点属性:
- label: 节点的标签文本。
A [label="Node A"];
- color: 节点的颜色。
A [color="red"];
- shape: 节点的形状,例如
ellipse
(默认)、circle
、box
、diamond
等。
A [shape="box"];
- style: 节点的样式,例如
filled
、dashed
、dotted
、bold
等。
A [style="filled"];
- fillcolor: 当节点的样式设置为
filled
时,此属性确定填充颜色。
A [style="filled", fillcolor="yellow"];
- fontsize: 节点标签的字体大小。
A [fontsize=16];
2. 边属性:
- label: 边的标签文本。
A -> B [label="Edge from A to B"];
- color: 边的颜色。
A -> B [color="blue"];
- style: 边的样式,例如
dashed
、dotted
、bold
等。
A -> B [style="dashed"];
- weight: 边的权重,该权重在布局图时会被考虑。较重的边会更短。
A -> B [weight=2];
- dir: 边的方向。例如
forward
(默认,有向边)、back
、both
、none
。
A -> B [dir="both"];
- arrowhead 和 arrowtail: 定义边的箭头的样式。例如
normal
、inv
、dot
、odot
、none
等。
A -> B [arrowhead="normal", arrowtail="dot"];
3. 全局属性:
你还可以设置图、节点或边的默认属性。这些属性会应用于没有明确设置这些属性的所有图、节点或边。
graph [bgcolor="gray"];
node [color="red", shape="ellipse"];
edge [color="blue"];
2)示例
这里有非常多的示例