linux下graphviz安装与使用

xiaoxiao2025-07-15  9

用命令行安装软件

apt-get install graphviz

sudo apt-get install graphviz graphviz-doc

这样会安装dot语言的执行文件,执行文件路径在

/usr/bin/dot

编写dot文件:

vim text.dot 

例如:

digraph G {         hello [shape=box];         world [style=filled, color="1,1,1"];         hello -> world [label="Yes"];     }

保存后,退出

编译时输出格式可以根据自己的需要来灵活选择,主要有一下三种:

dot -Tpng test.dot -o test.png dot -Tsvg test.dot -o test.svg

dot test.dot -Tpdf -o test.pdf

打开生成的图片

如果出现error:dot:cannot open text.dot

可能式text.dot格式的问题将里面的内容删除重写一下可能会好,我就是这样弄好的

简单介绍下DOT语言的语法:

无向图: 

graph graphname {      a -- b -- c;      b -- d;  }

有向图:

digraph graphname {      a -> b -> c;      b -> d;  }

边和节点的属性设置方法不一致,节点的属性被放置在只包含节点名称的表达式后,如下:

digraph G {         hello [shape=box];//设置节点属性         world [style=filled, color="1,1,1"];//节点多个属性用逗号分开         hello -> world [label="Yes"];//设置边的属性     }

转载请注明原文地址: https://www.6miu.com/read-5033138.html

最新回复(0)