日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GraphViz:2 DOT语法和相关应用

發(fā)布時間:2025/3/21 编程问答 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GraphViz:2 DOT语法和相关应用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、說明

1.1 Graphviz制圖概述

總的來說,Graphviz 支持兩類圖:

  • 無向圖?
  • 有向圖?

1.2 組成部分

  • node?節(jié)點
  • edge?邊
  • subgraph?子圖
  • attr?屬性

1.3 DOT文件

????????dot文件是一個文本腳本,是專門存儲有向圖,或無向圖的信息文件,通過dot指令可以將一個dot文件轉(zhuǎn)化成圖片,或pef文件,可視化完成。

二、 *.DOT文件要點----關(guān)于dot的語法

2.1 無向圖的語法

1)如何生成以下的無向圖?

2)語句如下:

? ? ? ? ? ? ? graph{ a--b; b--c; c--a;}

3)語法解釋:

  • ? ? ?graph{} 是圖的關(guān)鍵詞,任何圖都包含該語句;
  • ? ? ?a--b;是表示相鄰頂點的“有邊”關(guān)系,‘--’表示a頂點和b頂點可達,‘;’表該邊描述語句完畢。

5)輸出

將上述實現(xiàn)語句存入文本文件d:/new.dot,打開windows的cmd,進入cd d: 后,輸入:

dot? -T? ?jpg? ./new.dot? -o? new-grap.jpg

輸出完成,打開new-grap.jpg,得到:

???

圖1? ?無向圖的dot繪制案例 ( 左邊圖,不夠美觀,用graph{ a--{b,c}; b--c;} 語法代替生成右圖。 )

2.2 簡單有向圖的語法?

?1)如何生成以下的有向圖?

?2)語句如下:

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

3)語法解釋:

  • ? ? ?digraph{} 是有向圖的關(guān)鍵詞,任何圖都包含digraph{}或graph{};
  • ? ? ?a->b;是表示相鄰頂點的“有向邊”關(guān)系,‘->’表示a頂點和b頂點出入關(guān)系可達,‘;’表該邊描述語句完畢。

5)輸出

將上述實現(xiàn)語句存入文本文件d:/new.dot,打開windows的cmd,進入cd d: 后,輸入:

dot? -T? ?jpg? ./new.dot? -o? new-grap.jpg

輸出完成,打開new-grap.jpg,得到:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖2 有向圖的DOT繪制案例?

?三、 更豐富的dot的語法

1)帶標簽的語法結(jié)構(gòu)?

?

2)色彩豐富的圖

digraph {player[label = "player", color = Blue, fontcolor = Red, fontsize = 24, shape = box];game[label = "game", color = Red, fontcolor = Blue, fontsize = 24, shape = ellipse];player -> game[label = "play"] }

?3 在節(jié)點插入圖片?

digraph {c[shape = none, image = "./D06.png"]a -> b -> c;c -> d; }

??4 在節(jié)點插入圖片?

節(jié)點和連線的統(tǒng)一定義(先進行node、edge的統(tǒng)一定義,在定義數(shù)據(jù)的節(jié)點):

digraph {node[color = Red, fontsize = 24, shape = box]edge[color = Blue, style = "dashed"]c[shape = none, image = "./pic.png"]a -> b -> c;c -> d; }

?5 在一個圖中,嵌入子圖

digraph {label = visitNetrankdir = LRnode[color = Red, fontsize = 24, shape = box]edge[color = Blue, style = "dashed"]user[style = "filled", color = "yellow", fillcolor = "chartreuse"]subgraph cluster_cd{label = "server and browser"bgcolor = green;browser -> server}user -> computer;computer -> browser; }

?

?6 結(jié)構(gòu)視圖

注意點

1 用節(jié)點定義node[shape = record];定義節(jié)點是結(jié)構(gòu)

2 用label=“字符串” 定義結(jié)構(gòu)的內(nèi)容,用“|”分割開

3 用<結(jié)構(gòu)項標號>標明結(jié)構(gòu)的單項標號

3 用? 結(jié)構(gòu)體:單項標號->結(jié)構(gòu)體:單項標號? 表明關(guān)系連線

digraph {node[shape = record];struct1[label = "<f0> left|<f1> mid&#92; dle|<f2> right"];struct2[label = "<f0> one|<f1> two"];struct3[label = "hello&#92;nworld | {b|{c|<here> d|e}|f}|g|h"];struct1:f1 -> struct2:f0;struct1:f2 -> struct3:here; }

??7 樹形結(jié)構(gòu)

digraph tree {fontname = "PingFang-SC-Light"fontsize = 24node[shape = "plaintext"]1 -> 2;1 -> 3;2 -> 4;2 -> 5;3 -> 6;3 -> 7;4 -> 8;4 -> 9;5 -> 10;5 -> 11;6 -> 12;6 -> 13;7 -> 14;7 -> 15; }

8 繼承關(guān)系

digraph UML {node[fontname = "Courier New", fontsize = 10, shape = record];edge[fontname = "Courier New", fontsize = 10, arrowhead = "empty"];Car[label = "{Car | v : float\nt : float | run() : float}"]subgraph clusterSome{bgcolor = "yellow";Bus[label = "{Bus | | carryPeople() : void}"];Bike[label = "{bike | | ride() : void}"];}Bus -> CarBike -> Car}

?9 時序關(guān)系圖

digraph time {rankdir = "LR";node[shape = "point", width = 0, height = 0];edge[arrowhead = "none", style = "dashed"];{rank = "same"edge[style = "solided"];APP[shape = "plaintext"];APP -> step00 -> step01 -> step02 -> step03 -> step04 -> step05;}{rank="same";edge[style="solided"];SDK[shape="plaintext"];SDK -> step10 -> step11 -> step12 -> step13 -> step14 -> step15;}{rank="same";edge[style="solided"];AliPay[shape="plaintext"];AliPay -> step20 -> step21 -> step22 -> step23 -> step24 -> step25;}{rank="same";edge[style="solided"];Server[shape="plaintext"];Server -> step30 -> step31 -> step32 -> step33 -> step34 -> step35;}step00 -> step10 [label="sends order info", arrowhead="normal"];step11 -> step21 [label="open AliPay", arrowhead="normal"];step22 -> step12 [label="pay success", arrowhead="normal"];step13 -> step03 [label="pay success", arrowhead="normal"];step24 -> step34 [label="pay success", arrowhead="normal"]; }

三、.DOT的布局器參考

????????以下將說明這兩類圖的基本語法,同時,為了豐富圖像,頂點和邊都具有各自的屬性,比如形狀,顏色,填充模式,字體,樣式等。主要的布局器如下:

  • dot: 默認布局方式,主要用于有向圖;
  • neato:基于 sprint model 模型,又稱force-based 或者 energy minimized;
  • twopi:徑向布局,放射狀;
  • circo:圓環(huán)布局;
  • fdp:無向圖;
  • dotty:一個用于可視化與修改圖形的圖形用戶界面程序;
  • lefty:一個可以顯示 DOT 圖形的可編程控件,并允許用戶用鼠標在圖上執(zhí)行操作。

參考文章:

  • ?關(guān)于語法:GraphViz Examples and Tutorial (grevian.org)
  • GraphViz的其它用途:GraphViz的使用 - 簡書 (jianshu.com)
  • 使用Graphviz和DOT語言繪圖-百度經(jīng)驗 (baidu.com)
  • Graphviz 的中文文檔,Graphviz 中文文檔
  • Dot 語言介紹(想要更多了解的時候可以查看),Graphviz Dot 語言介紹
  • Python Graphviz 的入門文檔,Graphviz User Guide
  • Python Graphviz 的 Example 介紹,Graphviz 的例子
  • Graphviz 的下載,Graphviz Download
  • 使用 Graphviz 的例子,生成項目UML框架圖-pyreverse介紹
  • GraphViz Examples and Tutorial (grevian.org)

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的GraphViz:2 DOT语法和相关应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。