用户工具

站点工具


doc:g:graphviz

利用 GraphViz 绘制关联图

GraphViz 是AT&T实验室和Bell实验室开发的绘图工具,尤其擅长关联图。其描述语言是 dot。

FreeBSD 对这等优秀的软件,必然网罗旗下(/usr/ports/graphics/graphviz),读者也可以参考 http://www.graphviz.org/Gallery.php

本短文给出一个示例,源码是做 Association Rule Mining 时所得结果的片段。文件名是 sample.dot。

digraph sample {                                                                                                    
ranksep=3;
rankdir=LR;
ratio=auto;
node [fontsize=18,fontname="Arial",shape=none,nodesep=3];
edge [arrowhead=normal,arrowsize=0.7,len=.3,style="setlinewidth(1.5)"];
subgraph net1 {
edge[color="red"];
"whole milk"[shape = "ellipse", color = "white",fontsize=40];
"other vegetables, root vegetables" -> "whole milk"; 
"root vegetables, yogurt" -> "whole milk"; 
"pip fruit, tropical fruit" -> "whole milk"; 
"rolls/buns, tropical fruit" -> "whole milk"; 
"soda, tropical fruit" -> "whole milk"; 
"pastry, rolls/buns" -> "whole milk"; 
"pastry, soda" -> "whole milk"; 
"bottled water, rolls/buns" -> "whole milk";
}
"bottled water, yogurt"[shape = "ellipse", color = "white",fontsize=40];
subgraph net2 {
edge [color="blue"];
"other vegetables, tropical fruit" -> "bottled water, yogurt"; 
"soda, tropical fruit" -> "bottled water, yogurt"; 
"tropical fruit, whole milk" -> "bottled water, yogurt"; 
"rolls/buns, tropical fruit" -> "bottled water, yogurt"; 
"pip fruit, tropical fruit" -> "bottled water, yogurt"; 
"root vegetables, tropical fruit" -> "bottled water, yogurt"; 
"pastry, whole milk" -> "bottled water, yogurt"; 
"bottled beer, whole milk" -> "bottled water, yogurt";
}
"rolls/buns, yogurt"[shape = "ellipse", color = "white",fontsize=40];
subgraph net3 {
edge [color="green"];
"tropical fruit, whole milk" -> "rolls/buns, yogurt"; 
"other vegetables, tropical fruit" -> "rolls/buns, yogurt";
"root vegetables, tropical fruit" -> "rolls/buns, yogurt"; 
"soda, tropical fruit" -> "rolls/buns, yogurt"; 
"pip fruit, tropical fruit" -> "rolls/buns, yogurt"; 
"other vegetables, whole milk" -> "rolls/buns, yogurt"; 
"root vegetables, whole milk" -> "rolls/buns, yogurt"; 
"sausage, soda" -> "rolls/buns, yogurt";
}
} 

几个常用的命令

几个常见的命令,貌似输出不同,但其拓扑结构都是相同的。

dot -Tpng -o sample-dot.png sample.dot

twopi -Tpng -o sample-twopi.png sample.dot

circo -Tpng -o sample-circo.png sample.dot

fdp -Tpng -o sample-fdp.png sample.dot

再添一个例子

digraph RelationOfDistributions {
 ranksep=0.4;
 rankdir=LR;
 nodesep=0.5;
# ratio=fill;
 root=node9;
 node[shape=box,color=lightblue2, style=filled,fontname="/usr/local/share/fonts/TrueType/simsun.ttf",fontsize=40];
 edge [arrowhead=normal,style="setlinewidth(2)"];
 node0 [label="单点分布"];
 node1 [label="两点分布"];
 node2 [label="二项分布",shape=octagon];
 node3 [label="负二项分布",shape=octagon];
 node4 [label="几何分布"];
 node5 [label="Polya 分布"];
 node6 [label="超几何分布"];
 node7 [label="Poisson 分布",shape=ellipse,color=pink];
 node8 [label="均匀分布"];
 node9 [label="正态分布",shape=ellipse,color=pink];
 node10 [label="对数正态分布"];
 node11 [label="Laplace 分布"];
 node12 [label="Cauchy 分布",shape=ellipse,color=pink];
 node13 [label="Gamma 分布",shape=octagon];
 node131 [label="逆 Gamma 分布"];
 node14 [label="指数分布"];
 node15 [label="卡方分布",shape=ellipse,color=pink];
 node151 [label="逆卡方分布"];
 node16 [label="Beta 分布"];
 node17 [label="t 分布"];
 node18 [label="F 分布"];
 node19 [label="Pareto 分布"];
 node20 [label="Erlang 分布",shape=octagon];
# node21 [label="Gibbs 分布"];
 node22 [label="Weibull 分布"];
 node23 [label="Rayleigh 分布"];
 node24 [label="Maxwell 分布"];
 node25 [label="Wigner 半圆分布"];
 node26 [label="高维均匀分布"];
 node27 [label="多项分布"];
 node28 [label="Dirichlet 分布"];
 node29 [label="多元正态分布"];
 node30 [label="Wishart 分布",shape=octagon];
 node1 -> node0 [dir="both"];
 node1 -> node2 [dir="both"];
 node4 -> node3 [dir="both"];
 node5 -> node6;
 node9 -> node10 [dir="both"];
 node9 -> node15;
 node29 -> node9 [dir="both"];
 node29 -> node30;
 node29 -> node15;
 node27 -> node2;
 node8 -> node26 [dir="both"];
 node8 -> node11;
 node15 -> node18;
 node13 -> node131 [dir="both"];
 node13 -> node15;
 node151 -> node15 [dir="both"];
 node13 -> node14 -> node11;
 node13 -> node16 -> node25;
 node16 -> node8;
 node8 -> node14 [dir="both"];
 node19 -> node14 [dir="both"];
 node22 -> node14 [dir="both"];
 node9 -> node12;
 node8 -> node12;
 node9 -> node23;
 node22 -> node23;
 node14 -> node23;
 node9 -> node24;
 node15 -> node24;
 node15 -> node23;
 node17  -> node12;
 node17 -> node18;
 node13  -> node28 -> node16 -> node18;
 node13 -> node20;
 node20 -> node14 [dir="both"];
## Approximation relations
 edge[style=dashed];
 node5 -> node2;
 node6 -> node2;
 node2 -> node9;
 node7 -> node9;
 node15 -> node9;
 node16 -> node9;
 node17 -> node9;
 node13 -> node9;
 node3 -> node7;
 node2 -> node7;
 node18 -> node15;
}

/data/vhosts/wiki-data/pages/doc/g/graphviz.txt · 最后更改: 2013/01/05 04:45 由 IOU