Graphviz的是AT&T Labs Research开发的图形绘制工具软件。
Graphviz的是AT&T Labs Research开发的图形绘制工具,他可以很方便的用来绘制结构化的图形网络,支持多种格式输出,生成图片的质量和速度都不错.Graphviz本身是开源的产品,下载可以到 这里,以及他的演示界面 Graphviz在windows上和Linux上都可以顺利运行。
使用graphviz可以画流程图、状态图等,非常方便。
python画点边图基本代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from graphviz import Digraph dot = Digraph(comment='The Test Table') # 添加圆点A,A的标签是Dot A dot.node('A', 'Dot A') # 添加圆点 B, B的标签是Dot B dot.node('B', 'Dot B') # dot.view() # 添加圆点 C, C的标签是Dot C dot.node(name='C', label= 'Dot C',color='red') # dot.view() # 创建一堆边,即连接AB的两条边,连接AC的一条边。 dot.edges(['AB', 'AC', 'AB']) # dot.view() # 在创建两圆点之间创建一条边 dot.edge('B', 'C', 'test') # dot.view() # 获取DOT source源码的字符串形式 print(dot.source) dot.view() dot.render('test-table.gv', view=True) |
效果:
画多个子图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
from graphviz import Digraph grap_g = Digraph("G",format="pdf") sub_g0 = Digraph(comment="process1",graph_attr={"style":'filled',"color":'lightgrey'},node_attr={"style":"filled","color":"red"}) sub_g0.node("a0","a0") sub_g0.node("a1","a1") sub_g0.node("a2","a2") sub_g0.node("a3","a3") sub_g0.edge("a0","a1") sub_g0.edge("a1","a2") sub_g0.edge("a2","a3") sub_g0.edge("a3", "a0") sub_g1 = Digraph(comment="process1",graph_attr={"style":'filled'}) sub_g1.node("B","b0") sub_g1.node("C","b1") sub_g1.node("D","b2") sub_g1.node("E","b3") sub_g1.edges(["BC","CD","DE"]) grap_g.node( "start", label="start",shape="Mdiamond") grap_g.node( "end", label="end", shape="Mdiamond") grap_g.subgraph(sub_g0) grap_g.subgraph(sub_g1) grap_g.edge("start","a0") grap_g.edge("start","B") grap_g.edge("a1","E") grap_g.edge("D","a3") grap_g.edge("a3","end") grap_g.edge("E","end") grap_g.render('test-table2.gv', view=True) from graphviz import Digraph g = Digraph('测试图片') g.node(name='a',color='red') g.node(name='b',color='blue') g.edge('a','b',color='green') g.view() |
效果:
类似于这样的基于graphviz的流程图绘制工具,已经有开源模块了,叫Diagrams:
https://pythondict.com/python-paintings/python-draw-system-architecture/
好的,走一波友链?