DOT语言学习笔记

设置点和线的形状与颜色

digraph是有向图,graph是无向图。要注意,->和–都表示图中的一条边,但是前者用于有向图中,而后者用于无向图中,不能混用。

代码示例

diaGraph G{main -> parse -> executemain -> initmain -> cleanupexecute -> make_stringexecute -> printfinit -> make_stringmain -> printfexecute -> compare
}

然后在命令行(cmd)中运行此文件,

dot -T输出格式 程序文件名.dot -o 输出文件名.输出格式

我们可以手动设置图的属性,即设置图中边的属性与图中点的属性。

我们可以在每条边后面添加中括号,在其中设置边的相关属性,也可以使用edge设置边的默认值。点的属性设置方法相同,node表示点的默认值。

diGraph G{size = "4, 4"  /*设置图片尺寸为4 * 4(英寸)*/main[shape = box] /*设置点main形状为矩形,默认为椭圆形*/main -> parse[weight = 8]  /*设置main到parse的边的重要程度,默认为1*/parse -> executemain -> init[style = dotted] /*设置main到init的边的样式为点,默认为实线*/main -> cleanupexecute -> {make_string printf} /*一次连接两条边,以隔开目标点*/init -> make_stringedge[color = red]  /*将此语句后的边的颜色设置为红色*/main -> printf[style = bold, label = "100 times"]node[shape = box, style = filled, color = ".7 .3 1.0"] /*设置此语句后的点的默认属性, 其中color的值采用RGB标准*/make_string[label = "make a\nstring"]execute -> comparecompare -> return
}

此外,还可以使用dir设置每条边的箭头方向,有forward(default),back,both,nonc,分别表示前向,反向,双向和无。如下所示:

digraph G{A -> B[dir = both]B -> C[dir = nonc]C -> D[dir = back]D -> A[dir = forward]
}

点的属性除了record和Mrecord这两种之外,其他的形状都是多边形,而我们可以对多边形进行设置。sides用于设置边数,peripheries用于设置多边形外框的层数,regular = true可以使你的多边形是一个规则的多边形,orientation = * 可以让你的多边形旋转*角度,skew后面跟一个(-1.0~1.0)的小数,能使你的图形斜切一个角度,distortion则可以令你的图形产生透视效果。

digraph G{a -> b -> cb ->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]e[shape = polygon, sizes = 4, distortion = .7]
}
digraph G{A -> BA[orientation = 15, regular = true, shape = polygon, sides = 8, peripheries = 4, color = red, style = filled]B[shape = polygon, sides = 4, skew = 0.5, color = blue]
}

record与Mrecord的区别就是Mrecord的角是圆的,而record是由横竖的矩形组成的图形。

digraph G{node[shape = record]struct1[label = "<f0> left | <f1> middle | <f2> right"]struct2[label = "<f0> one | <f1> two"]struct3[label = "hello \nworld | {b | {c | <here> d | e} | f} | g | h"]struct1 -> struct2struct1 -> struct3
}

当你的线与线的label较多时,可以设置线的属性decorate=true使得每条线与其属性之间产生连线。你还可以为每条线设置属性headlabel,taillabel,给每条线的起始点和终点设置属性,它们的颜色由labelfontcolor决定,而label的颜色由fontcolor来决定。

graph G{label = "我爱你" /*为图设置标签*/labelloc = b    /*图标签的位置在底部,也可以设置为r到顶部*/labeljust = l   /*图标签的位置在左边,也可以设置为r到右边*/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 = "d1", taillabel = "c1", label = "c1 - d1"]
}

在dot语言中,我们可以使用html语言制作表格。在label后添加<>,而不是""就能添加html语言。

digraph html{abc[shape = none, margin = 0, label = <<TABLE BORDER = "0" CELLBORDER = "1" CELLSPACING = "0" CELLPADDING = "4"><TR><TD ROWSPAN = "3"><FONT COLOR = "red">hello</FONT><BR/>world</TD><TD COLSPAN = "3">b</TD><TD ROWSPAN = "3" BGCCOLOR = "lightgrey">g</TD><TD ROWSPAN = "3">h</TD></TR><TR><TD>c</TD><TD PORT = "here">d</TD><TD>e</TD></TR><TR><TD COLSPAN = "3">f</TD></TR></TABLE>>]
}

设置点,线的位置以及子图的概念

图中的线默认是从上往下的,我们可以通过在文件的最上层设置rankdir=LR将其改为从左往右。同理,rankdir可以设置为TB(默认),BT,RL。

当图中时间表之类的东西时,我们可能需要点排列成一行(列),这时我们就需要rank,在花括号中设置rank=same,然后将需要并排的点一次输入。

digraph G{rankdir = LR{node[shape = plaintext]1995 -> 1996 -> 1997 -> 1998 -> 1999 -> 2000 -> 2001}{node[shape = box, style = filled]WAR3 -> Xhero -> Footman -> DOTAWAR3 -> Battleship}{{rank = same 1996 WAR3}{rank = same 1998 Xhero Battleship}{rank = same 1999 Footman}{rank = same 2001 DOTA}}
}

设立一条边时,我们可以制定这条边从起点的哪个位置出发,到终点的哪个位置结束。控制符有"n",“ne”,“e”,“se”,“s”,“sw”,“w"和"nw”,具体效果见下:

digraph G{node[shape = box]c:n -> d[label = n]c1:ne -> d1[label = ne]c2:e -> d2[label = e]c3:se -> d3[label = se]c4:s -> d4[label = s]c5:sw -> d5[label = sw]c6:w -> d6[label = w]c7:nw -> d7[label = nw]
}

我们也可以在record中给点定义一些port,以确定record中哪个部分用于连线。

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>"]A: f0: sw -> B: f1A: f2: se -> C: f1B: f0: sw -> D: f1B: f2: se -> E: f1
}

我们可以借此构建一个Hash表。

digraph G{nodesep = .05rankdir = LRnode[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: nnode0: f1 -> node2: nnode0: f2 -> node3: nnode0: f5 -> node4: nnode0: f6 -> node5: nnode2: p -> node6: nnode4: p -> node7: n
}

画一个子图就是subgraph cluster#,必须有clutser前缀。这里"#“代表任意字符,当然为了便于区分,最好将”#"设置为非英文字母。

digraph G{subgraph cluster1{node[style = filled, color = white]style = filledcolor = lightgreya0 -> a1 -> a2 -> a3label = "process1"}subgraph cluster2{node[style = filled]color = blueb0 -> b1 -> b2 -> b3label = "process2"}start -> a0start -> b0a1 -> b3b2 -> a3a3 -> a0a3 -> endb3 -> endstart[shape = Mdiamond]end[shape = Msquare]
}

如果你想将一条边连到一个子图的边界上,先输入compound=true,然后就能用lhead和ltail设置连接的子图。

附录

  • 点,边和图的属性

    http://www.graphviz.org/doc/info/attrs.html

  • 点的形状

    http://www.graphviz.org/doc/info/shapes.html

  • 颜色设置

    http://www.graphviz.org/doc/info/colors.html

十分钟了解绘图神器——Graphviz学习笔记相关推荐

  1. catBoost 神器的学习笔记

    catBoost 神器的学习笔记,记录自己看原文章的心得.第一次发文,中间有些部分也是个人理解,不足之处,敬请谅解.欢迎扔砖 ^=^catBoost 原文的标题是 "CatBoost :un ...

  2. jquery 绘图工具 flot 学习笔记

    原文地址为: jquery 绘图工具 flot 学习笔记 今天想做一个统计图表,像163博客的流量统计一样的,借助 flot 实现了,而且很简单. flot网址:http://code.google. ...

  3. OpenCV学习笔记(十六)——CamShift研究 OpenCV学习笔记(十七)——运动分析和物体跟踪Video OpenCV学习笔记(十八)——图像的各种变换(cvtColor*+)imgproc

    OpenCV学习笔记(十六)--CamShift研究 CamShitf算法,即Continuously Apative Mean-Shift算法,基本思想就是对视频图像的多帧进行MeanShift运算 ...

  4. 深度学习(二十六)Network In Network学习笔记-ICLR 2014

    Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/details/50458190 作者:hjimce 一.相关理论 本篇 ...

  5. 深度学习(四十二)word2vec词向量学习笔记

    word2vec词向量学习笔记 原文地址:http://blog.csdn.net/hjimce/article/details/51564783 个人微博:黄锦池-hjimce 一.使用原版word ...

  6. 深度学习(二十六)Network In Network学习笔记

    Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/details/50458190 作者:hjimce 一.相关理论 本篇 ...

  7. 绘图神器 —— Graphviz 绘制数据结构相关图形

    复杂标签 digraph graphname{/* 把节点的形状设置为 record,默认的是圆角矩形 */node [shape = record];root [label = "left ...

  8. 【代码质量】-阿里巴巴java开发手册(代码质量提升神器)学习笔记

    前言:<阿里巴巴 Java 开发手册>是阿里巴巴集团技术团队的集体智慧结晶和经验总结,有了这些前人总结的经验,可以帮助我们写出高质量的代码,同时可以减少Bug数量,少踩坑,提高代码的可读性 ...

  9. graphviz linux 运行,绘图工具Graphviz学习使用

    起因 最近完成了研究生毕业设计,在写毕业论文时,老师曾经推荐使用代码来画相关的图,当时时间有些紧,所以没有这样做.最近在看 rapidjson 的文档,看到 miloyip 文档中的图都是用 dot ...

最新文章

  1. UA MATH564 概率论 Dirichlet分布
  2. 文件逆序改为正序脚本
  3. 关于vue项目中添加less,less-loader不能运行的问题
  4. 韩顺平php教程笔记,PHP笔记,韩顺平php笔记_PHP教程
  5. 验证客户端和服务端可以传输经SM4加密的密文数据,从而验证发送数据已使用服务器密码机进行SM4加密,而不是随便的字符串乱码
  6. WCF Data Services 基础
  7. 20 ide配置快捷键补全提示 win
  8. 管理数据,应用程序和主机安全-C
  9. [BZOJ2157]旅游(树链剖分/LCT)
  10. 鸿蒙开发之拨打电话号码
  11. android: unexpected end of stream
  12. c语言读取三菱plc数据,三菱plc怎么读取程序_电脑读取三菱PLC数据简单方法
  13. SPSS独立样本t检验结果分析
  14. 推荐 21 款博主常用 Windows 软件
  15. 【Audio】基于STM32 I2S移植WM8978 Audio Codec驱动
  16. 常见的两种解空间 全排列与幂集
  17. 少年派的奇幻漂流-解读与感悟
  18. EBS开发_fnd_message使用
  19. 国内有免费“免费虚拟主机““免费云服务器”吗?
  20. 蓝牙耳机选什么好?5款主打高性价比的蓝牙耳机推荐

热门文章

  1. java毕业设计选题基于JavaWeb项目实现的高校学生在线选课系统
  2. 7z001怎么解压在安卓手机上面_安卓手机时间怎么显示在中间 时间居中设置教程...
  3. 《老鹰抓小鸡》将代表中国动画电影走出国门,走向世界,yyds❤
  4. 云网融合驱动数据中心技术聚变
  5. stm32之蓝牙无线超声波测距
  6. 有人晒出程序员聚餐照片,网友:根据头发量能看出技术水平高低!
  7. 【21SR】Designing a Practical Degradation Model for Deep BlindImage Super-Resolution
  8. 裁判文书网 爬虫 升级最新版本0.7 更新时间2020-12-17
  9. springboot笔记(硅谷)
  10. 计算机科学读ms还是phd好,美研申请中怎样判断适合读硕士(MS)还是博士(PhD)?