node 节点属性如下 :

Name Default Values
color black node shape color
comment   any string (format-dependent)
distortion 0.0 node distortion for shape=polygon
fillcolor lightgrey/black node fill color
fixedsize false label text has no affect on node size
fontcolor black type face color
fontname Times-Roman font family
fontsize 14 point size of label
group   name of node’s group
height .5 height in inches
label node name any string
layer overlay range all, id or id:id
orientation 0.0 node rotation angle
peripheries shape-dependent number of node boundaries
regular false force polygon to be regular
shape ellipse node shape; see Section 2.1 and Appendix E
shapefile   external EPSF or SVG custom shape file
sides 4 number of sides for shape=polygon
skew 0.0 skewing of node for shape=polygon
style   graphics options, e.g. bold, dotted, filled; cf. Section 2.3
URL   URL associated with node (format-dependent)
width .75 width in inches
z 0.0 z coordinate for VRML output

edge 边框属性如下:

Name Default Values
arrowhead normal style of arrowhead at head end
arrowsize 1.0 scaling factor for arrowheads
arrowtail normal style of arrowhead at tail end
color black edge stroke color
comment   any string (format-dependent)
constraint true use edge to affect node ranking
decorate   if set, draws a line connecting labels with their edges
dir forward forward, back, both, or none
fontcolor black type face color
fontname Times-Roman font family
fontsize 14 point size of label
headlabel   label placed near head of edge
headport   n,ne,e,se,s,sw,w,nw
headURL   URL attached to head label if output format is ismap
label   edge label
labelangle -25.0 angle in degrees which head or tail label is rotated off edge
labeldistance 1.0 scaling factor for distance of head or tail label from node
labelfloat false lessen constraints on edge label placement
labelfontcolor black type face color for head and tail labels
labelfontname Times-Roman font family for head and tail labels
labelfontsize 14 point size for head and tail labels
layer overlay range all, id or id:id
lhead   name of cluster to use as head of edge
ltail   name of cluster to use as tail of edge
minlen 1 minimum rank distance between head and tail
samehead   tag for head node; edge heads with the same tag are
sametail   merged onto the same port
style   tag for tail node; edge tails with the same tag are merged onto the same port
taillabel   graphics options, e.g. bold, dotted, filled; cf. Section 2.3
tailport   label placed near tail of edge n,ne,e,se,s,sw,w,nw
tailURL   URL attached to tail label if output format is ismap
weight 1 integer cost of stretching an edge

Digraph 图属性如下:

Name Default Values
bgcolor   background color for drawing, plus initial fill color
center false center drawing on page
clusterrank local may be global or none
color black for clusters, outline color, and fill color if fillcolor not defined
comment   any string (format-dependent)
compound false allow edges between clusters
concentrate false enables edge concentrators
fillcolor black cluster fill color
fontcolor black type face color
fontname Times-Roman font family
fontpath   list of directories to search for fonts
fontsize 14 point size of label
label   any string
labeljust centered ”l” and ”r” for left- and right-justified cluster labels, respectively
labelloc top ”t” and ”b” for top- and bottom-justified cluster labels, respectively
layers   id:id:id…
margin .5 margin included in page, inches
mclimit 1.0 scale factor for mincross iterations
nodesep .25 separation between nodes, in inches.
nslimit   if set to f, bounds network simplex iterations by (f)(number of nodes) when setting x-coordinates
nslimit1   if set to f, bounds network simplex iterations by (f)(number of nodes) when ranking nodes
ordering   if out out edge order is preserved
orientation portrait if rotate is not used and the value is landscape, use landscape orientation
page   unit of pagination, e.g. “8.5,11”
pagedir BL traversal order of pages
quantum   if quantum ¿ 0.0, node label dimensions will be rounded to integral multiples of quantum
rank   same, min, max, source or sink
rankdir TB LR (left to right) or TB (top to bottom)
ranksep .75 separation between ranks, in inches.
ratio   approximate aspect ratio desired, fill or auto
remincross   if true and there are multiple clusters, re-run crossing minimization
rotate   If 90, set orientation to landscape
samplepoints 8 number of points used to represent ellipses and circles on output (cf. Appendix C
searchsize 30 maximum edges with negative cut values to check when looking for a minimum one during network simplex
size   maximum drawing size, in inches
style   graphics options, e.g. filled for clusters
URL   URL associated with graph (format-dependent)
from graphviz import Graph
from graphviz import Digraph # 绘制无向图
def draw_Graph():
# 创建对象,设置对象属性
dot = Graph(name='无向图', filename=r'D:\Cache\python\无向图', format='png')
# 设置节点属性, 修改 fontname 属性可解决中文输出乱码问题
dot.node_attr.update(shape='ellipse', color='black', fillcolor='lightgrey', fontcolor='black', fontsize='',
fontname='Microsoft YaHei', width='', height='', style='bold')
# 创建节点, 设置节点名字、内容
dot.node('A', '小朋友')
dot.node('B', '小学生')
dot.node('C', '初中生')
dot.node('D', '高中生')
dot.node('E', '大学生')
dot.node('F', '研究生')
dot.node('G', '博士生')
dot.node('H', '医生')
dot.node('I', '老师')
dot.node('J', '程序员')
dot.node('K', '会计')
dot.node('L', '公务员')
dot.node('M', '教授')
# 设置边属性
dot.edge_attr.update(color='black', fontcolor='black', fontsize='', fontname='Microsoft YaHei')
# 创建单边,设置边内容
dot.edge('A', 'B', '升级')
dot.edge('B', 'C', '升级')
dot.edge('C', 'D', '升级')
dot.edge('D', 'E', '升级')
dot.edge('E', 'F', '升级')
dot.edge('F', 'G', '升级')
# 创建多边,不能设置边内容
dot.edges(['EI', 'FI', 'GI', 'FH', 'GH', 'EJ', 'FJ', 'GJ', 'EK', 'FK', 'GK', 'EL', 'FL', 'GL', 'GM'])
# 打印生成的源代码,pdf 格式无法打印
print(dot.source)
# 保存图片,不显示图片
dot.render(filename='无向图', directory=r'D:\Cache\python')
# 保存图片,并显示图片
dot.view(filename='无向图', directory=r'D:\Cache\python') # 绘制有向图
def draw_Digraph():
# 创建对象,设置对象属性
dot = Digraph(name='有向图', filename=r'D:\Cache\python\有向图', format='pdf')
# 设置节点属性, 修改 fontname 属性可解决中文输出乱码问题
dot.node_attr.update(shape='ellipse', color='black', fillcolor='lightgrey', fontcolor='black', fontsize='',
fontname='Microsoft YaHei', width='', height='', style='bold')
# 创建节点, 设置节点名字、内容
dot.node('A', '小朋友')
dot.node('B', '小学生')
dot.node('C', '初中生')
dot.node('D', '高中生')
dot.node('E', '大学生')
dot.node('F', '研究生')
dot.node('G', '博士生')
dot.node('H', '医生')
dot.node('I', '老师')
dot.node('J', '程序员')
dot.node('K', '会计')
dot.node('L', '公务员')
dot.node('M', '教授')
# 设置边属性, arrowhead 为前端箭头样式, arrowsize 为箭头缩放比例, minlen 为边头部和尾部的距离, pnewidth 为边宽度
dot.edge_attr.update(color='black', fontcolor='black', fontsize='', fontname='Microsoft YaHei',
arrowhead='diamond', arrowsize='2.0', minlen='', penwidth='', style='dashed')
# 创建单边,设置边内容
dot.edge('A', 'B', '升级')
dot.edge('B', 'C', '升级')
dot.edge('C', 'D', '升级')
dot.edge('D', 'E', '升级')
dot.edge('E', 'F', '升级')
dot.edge('F', 'G', '升级')
# 创建多边,不能设置边内容
dot.edges(['EI', 'FI', 'GI', 'FH', 'GH', 'EJ', 'FJ', 'GJ', 'EK', 'FK', 'GK', 'EL', 'FL', 'GL', 'GM'])
# 保存图片,不显示图片
dot.render(filename='有向图', directory=r'D:\Cache\python')
# 保存图片,并显示图片
dot.view(filename='有向图', directory=r'D:\Cache\python') if __name__ == '__main__':
draw_Graph()

graphviz 的使用教程的更多相关文章

  1. 转+更新 Graphviz 教程,例子+ 高级应用 写代码,编程绘制架构图(分层拓扑图) 转自官网

    1. Graphviz介绍 Graphviz是大名鼎鼎的贝尔实验室的几位牛人开发的一个画图工具. 它的理念和一般的“所见即所得”的画图工具不一样,是“所想即所得”. Graphviz提供了dot语言来 ...

  2. 用doxygen+graphviz自动化生成代码文档(附详细教程)

    一.引子 用这两个工具可以自动的遍历代码,并且产生代码文档,我们先来看看效果,然后放出这两个工具的下载地址. 二.工具的下载地址 doxygen:http://www.stack.nl/~dimitr ...

  3. windows下Graphviz安装及入门教程

    下载安装配置环境变量 intall 配置环境变量 验证 基本绘图入门 graph digraph 一个复杂的例子 和python交互 发现好的工具,如同发现新大陆.有时,我们会好奇,论文中.各种专业的 ...

  4. graphviz 布局和子图,表格教程

    有了这三个利器,就搞定架构图了. 子图间互相调用要开启 http://graphviz.org/pdf/dotguide.pdf

  5. graphviz layer 教程(非布局)

    官方 pdf 上讲解的很少,没有图片. http://www.graphviz.org/wiki/how-use-drawing-layers-overlays 这里有图片,但是又没有说如何生成. 直 ...

  6. 开启基本数据结构和算法之路--初识Graphviz

    在我的Linux刀耕开荒阶段,就想开始重拾C,利用C实现常用的基本数据结构和算法,而数据结构和算法的掌握的熟练程度正是程序的初学者与职业程序员的分水岭. 那么怎么开启这一段历程呢? 按照软件工程的思想 ...

  7. 使用 Graphviz 画拓扑图

    使用 Graphviz 画拓扑图 0)前述 本文着重讲一下 Graphviz 的风格控制,基础一些的就不在这里讲啦. graphviz 的主页是http://www.graphviz.org/. Gr ...

  8. KinectV1+Ubuntu 14.04安装教程

    前言      个人理解错误的地方还请不吝赐教,转载请标明出处,内容如有改动更新,请看原博:http://www.cnblogs.com/hitcm/      如有任何问题,feel free to ...

  9. 代码文档生成工具-Doxygen生成CHM和RTF图文教程

    Doxygen是一种开源跨平台的,以类似JavaDoc风格描述的文档系统,可以从一套归档源文件开始,生成chm格式的文档.本文主要讲解如何在winddows下安装doxygen.     1.下载do ...

随机推荐

  1. H3C 帧中继虚电路

  2. jq实现二级菜单/下拉菜单

    https://www.cnblogs.com/sandraryan/ 不是很难,直接上代码~ 有写注释 <!DOCTYPE html> <html lang="en&qu ...

  3. uva 624 CD (01背包)

      CD  You have a long drive by car ahead. You have a tape recorder, but unfortunately your best musi ...

  4. java throw

    自行抛出一个异常对象,抛出异常类的对象: 若throw抛出的是Runtime异常: 程序可以显示使用try...catch来捕获并处理,也可以不管,直接交给方法调用者处理: 若throw抛出Check ...

  5. 模版——KMP

    #include <iostream> #include <cstdio> #include <cstring> ; int f[maxn]; char P[max ...

  6. windows命令行下redis读取中文字符乱码

    我在eclipse上对redis进行了一个操作,添加了一个中文字符串进去,可以看到是添加成功了的 但是在命令行中读取的时候却成了乱码,如下图所示 这是因为windows命令行的编码是gbk 可以通过如 ...

  7. 深度优先遍历 and 广度优先遍历

    深度优先遍历 and 广度优先遍历 遍历在前端的应用场景不多,多数是处理DOM节点数或者 深拷贝.下面笔者以深拷贝为例,简单说明一些这两种遍历.

  8. java 面试题之交通灯管理系统

    需求: 交通灯管理系统的项目需求 Ø 异步随机生成按照各个路线行驶的车辆. 例如: 由南向而来去往北向的车辆 ---- 直行车辆 由西向而来去往南向的车辆 ---- 右转车辆 由东向而来去往南向的车辆 ...

  9. H3C 根据子网掩码计算子网数

  10. ioctl 命令的实现

    ioctl 的 scull 实现只传递设备的配置参数, 并且象下面这样容易: switch(cmd) { case SCULL_IOCRESET: scull_quantum = SCULL_QUAN ...