有向图的分层绘制
有向图的分层绘制
LayeredGraphPlot 试图在一系列层次中画出图的各个顶点,其中把主导顶点放置在顶部,并逐步画出低层次的顶点.
| LayeredGraphPlot[{vi1->vj1,vi2->vj2,…}] | |
以分层形式生成图的一个图线,其中顶点 vik 与顶点 vjk 相连 | |
| LayeredGraphPlot[{{vi1->vj1,lbl1},…}] | |
把标签 lblk 与图中的边相联系 | |
| LayeredGraphPlot[g,pos] | 在图线中的位置 pos 上放置主导顶点 |
| LayeredGraphPlot[m] | 产生由邻接矩阵 m 表示的分层图 |
LayeredGraphPlot 绘制一个图,使得边的指向主要是向下的. LayeredGraphPlot 的第二个变量指明根节点的位置. 该变量的可能值为 Right、Left、Top 和 Bottom.
LayeredGraphPlot[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5, 6 -> 3}, VertexLabels -> Automatic]LayeredGraphPlot[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5, 6 -> 3}, Left, VertexLabels -> Automatic]由于浮点的不同,LayeredGraphPlot 可能会在不同的平台上,产生稍有不同的输出.
选项名 | 默认值 | |
| DataRange | Automatic | 所产生的顶点坐标的范围 |
| DirectedEdges | True | 是否把边显示为有向箭头 |
| EdgeLabels | Automatic | 是否包含对边给出的标签 |
| EdgeShapeFunction | Automatic | 对边给出明确的图形函数 |
| MultiedgeStyle | Automatic | 如何在顶点之间绘制重边 |
| "PackingLayout" | Automatic | 用于排列分量的方法 |
| PlotRangePadding | Automatic | 在图线周边填充的空白量 |
| PlotStyle | Automatic | 绘制对象所采用的样式 |
| SelfLoopStyle | Automatic | 如何绘制连接一个顶点自身的边 |
| VertexCoordinateRules | Automatic | 明确的顶点坐标的规则 |
| VertexLabels | Automatic | 是否把顶点名称显示为标签 |
| VertexRenderingFunction | Automatic | 对顶点给出明确的图形函数 |
LayeredGraphPlot 的选项.
DirectedEdges
LayeredGraphPlot[{4 -> 3, 5 -> 2, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4}, DirectedEdges -> False, VertexLabels -> Automatic]EdgeLabels
EdgeLabels 选项指定是否并且如何显示对边给定的标签. 该选项的可能值为 All、None 或者 Automatic. 该选项的默认值为 Automatic,在默认值下,显示图中给定的边标签.
LayeredGraphPlot[{1 -> 5, 1 -> 6, 2 -> 4, 2 -> 6, 3 -> 4, 3 -> 5, {3 -> 6, "edge 3->6"}, 4 -> 6, 5 -> 6}, VertexLabels -> Automatic]使用 Tooltip[vi->vj,lbl] 指定一条边的工具提示条. 把光标放置在顶点3和顶点6之间的边上,以及顶点3和顶点5之间的边标签上,就可以看到工具提示条:
LayeredGraphPlot[{1 -> 5, 1 -> 6, 2 -> 4, 2 -> 6, 3 -> 4, {3 -> 5, Tooltip[ "edge 3->5", "3->5"]}, Tooltip[3 -> 6, "3->6"], 4 -> 6, 5 -> 6}, VertexLabels -> Automatic]EdgeShapeFunction
EdgeShapeFunction 选项指定了图的边的图形表示方法. 该选项的可能值为 Automatic、None 或者是一个给出图形基元和指令的合理组合的函数. 使用默认设置 Automatic,对每条边使用深红色的线绘制. 当设置EdgeShapeFunction->None 时,则不绘制边.
LayeredGraphPlot[Table[1, {10}, {10}], EdgeShapeFunction -> None, VertexLabels -> Automatic]设置 EdgeShapeFunction->g 时,每条边使用由图形基元和由函数 g 给定的指令绘制. 它可以采用三个或多个变量,形如 g[{ri,…,rj},{vi,vj},lblij,…],其中 ri、rj 是边的起点或终点的坐标,vi、vj 是起始和终止顶点,而 lblij 是为边指定的任意标签或者或者 None. EdgeShapeFunction->g 的明确设置重载 EdgeLabels 和 DirectedEdges 的设置.
LayeredGraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 1, 11 -> 12, 12 -> 13, 13 -> 14, 14 -> 15, 15 -> 16, 16 -> 17, 17 -> 11, 1 -> 11, 2 -> 12, 3 -> 13, 4 -> 14, 5 -> 15, 6 -> 16, 7 -> 17}, EdgeShapeFunction -> ({GrayLevel[0.5], Arrow[#1, 0.3]}&)]LayeredGraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4, 1 -> 4, 3 -> 5, 3 -> 3}, EdgeShapeFunction -> ({If[First[#2] === Last[#2], Red, StandardGreen], Arrow[#1, .1]}&)]MultiedgeStyle
选项 MultiedgeStyle 指定是否在两个顶点之间绘制重边. MultiedgeStyle 的可能值为 Automatic(默认)、True、False 或者一个正实数. 在默认设置 MultiedgeStyle->Automatic 下,对于由规则列表指定的图显示重边,而如果图由邻接矩阵指定,则不显示重边. 设置 MultiedgeStyle->δ 时,重边以尺度化的距离 δ 展开.
LayeredGraphPlot[{1 -> 2, 2 -> 1, 1 -> 2, 1 -> 2, 2 -> 3, 3 -> 5, 4 -> 5, 5 -> 6, 5 -> 1}, VertexLabels -> Automatic]LayeredGraphPlot[(| | | | | | |
| :- | :- | :- | :- | :- | :- |
| 0 | 3 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 |), VertexLabels -> Automatic]LayeredGraphPlot[{1 -> 2, 2 -> 1, 1 -> 2, 1 -> 2, 2 -> 3, 3 -> 5, 4 -> 5, 5 -> 6, 5 -> 1}, MultiedgeStyle -> 0.25, VertexLabels -> Automatic]PackingLayout
选项 "PackingLayout" 指定用来排列非连通分量的方法. 该选项的可能值为 Automatic(默认)、"ClosestPacking"、"ClosestPackingCenter"、"Layered"、"LayeredLeft"、"LayeredTop" 和 "NestedGrid". 设置 "PackingLayout"->"ClosestPacking" 时,使用位四角法(polyomino method)[6] 从左上角开始排列并且使分量的距离尽可能接近. 设置 "PackingLayout"->"ClosestPackingCenter" 时,从中心开始排列分量. 设置 "PackingLayout"->"Layered" 时,从左上角开始分层排列. 设置 "PackingLayout"->"LayeredLeft" 或者 "PackingLayout"->"LayeredTop" 时,分别从上/左开始分层排列分量. 设置 "PackingLayout"->"NestedGrid" 时,在嵌套网格中排列各分量. 典型默认设置为 "PackingLayout"->"Layered",从最大边界框区域中的分量开始进行排列.
LayeredGraphPlot[Table[i -> Mod[i ^ 3, 221], {i, 0, 221}], DirectedEdges -> False]LayeredGraphPlot[Table[i -> Mod[i ^ 3, 221], {i, 0, 221}], GraphLayout -> {"PackingLayout" -> "ClosestPackingCenter"}, DirectedEdges -> False]PlotRangePadding
PlotStyle
LayeredGraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 1, 6 -> 5, 7 -> 5, 5 -> 4, 9 -> 8, 10 -> 8, 8 -> 3, 12 -> 11, 13 -> 11, 11 -> 1, 15 -> 14, 16 -> 14, 14 -> 2}, VertexLabels -> Automatic, PlotStyle -> {Red, Arrowheads[{{0.1, 0.8}}], Thickness[0.02]}]SelfLoopStyle
选项 SelfLoopStyle 指定是否以及如何对与自身连接的顶点绘制自循环(loop). 该选项的可能值为 Automatic (默认)、True、False 或者一个正实数. 设置 SelfLoopStyle->Automatic 时,如果图由规则列表指定,则显示自循环,但是如果由邻接矩阵给定,则不显示. 设置 SelfLoopStyle->δ 时,自循环使用直径 δ 绘制(相对于平均边长).
LayeredGraphPlot[{3 -> 2, 4 -> 1, 4 -> 3, 5 -> 1, 5 -> 2, 6 -> 1, 6 -> 2, 6 -> 3, 6 -> 4, 6 -> 5, 1 -> 1, 1 -> 1}, VertexLabels -> Automatic]LayeredGraphPlot[(| | | | | | |
| :- | :- | :- | :- | :- | :- |
| 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 2 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 |), VertexLabels -> Automatic]LayeredGraphPlot[{3 -> 2, 4 -> 1, 4 -> 3, 5 -> 1, 5 -> 2, 6 -> 1, 6 -> 2, 6 -> 3, 6 -> 4, 6 -> 5, 1 -> 1, 1 -> 1}, VertexLabels -> Automatic, SelfLoopStyle -> 0.3]VertexCoordinates
LayeredGraphPlot[{1 -> 3, 1 -> 4, 2 -> 4, 2 -> 5, 3 -> 5, 6 -> 7, 7 -> 8, 8 -> 9, 9 -> 10, 6 -> 10, 1 -> 6, 2 -> 7, 3 -> 8, 4 -> 9, 5 -> 10}, VertexCoordinates -> {{0.309017, 0.951057}, {-0.809017, -0.587785}, {0.309017, -0.951057}, {-0.809017, 0.587785}, {1., 0}, {0.618034, 1.90211}, {-1.61803, 1.17557}, {-1.61803, -1.17557}, {0.618034, -1.90211}, {2., 0}}]LayeredGraphPlot[{1 -> 3, 1 -> 4, 2 -> 4, 2 -> 5, 3 -> 5, 6 -> 7, 7 -> 8, 8 -> 9, 9 -> 10, 6 -> 10, 1 -> 6, 2 -> 7, 3 -> 8, 4 -> 9, 5 -> 10}]VertexLabels
选项 VertexLabels 指定是否把顶点名称显示为标签. 该选项的可能值为 All、None 和 Automatic(默认). VertexLabels->All 显示标签. 对于由邻接矩阵指定的图,顶点标签采用连续整数
,其中 n 是矩阵的大小. 对于由规则列表指定的图,标签是在规则中使用的表达式.VertexLabels->None 把每个顶点显示为一个点. 用户也可以在规则列表的任意位置中使用 Tooltip[vk,vlbl] 来为顶点 vk 指定其它工具提示条.
LayeredGraphPlot[(| | | | | |
| :- | :- | :- | :- | :- |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 |), VertexLabels -> Automatic]LayeredGraphPlot[{"A" -> "B", "A" -> "a", "B" -> "C", "C" -> "A"}, VertexLabels -> Automatic]LayeredGraphPlot[{"A" -> "B", "A" -> "a", "B" -> "C", "C" -> "A"}, VertexLabels -> Placed[Automatic, Tooltip]]VertexShapeFunction
VertexShapeFunction 选项指定图的边的图形表示. 该选项的可能值为 Automatic、None、或者是一个给出图形基元和指令的合理组合的函数. 使用默认设置 Automatic,顶点显示为点.
g = {5 -> 3, 5 -> 4, 6 -> 2, 6 -> 4, 7 -> 1, 7 -> 4, 7 -> 5, 7 -> 6};LayeredGraphPlot[g]LayeredGraphPlot[g, VertexShapeFunction -> None]设置 VertexShapeFunction->g 时,每个顶点使用由 g[ri,vi,…] 给定的图形基元绘制,其中 ri 是顶点坐标,而 vi 是顶点标签. VertexShapeFunction->g 的明确设置重载 VertexLabels 的设置.
LayeredGraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 8 -> 1, 1 -> 9, 2 -> 9, 3 -> 10, 4 -> 10, 6 -> 11, 5 -> 11, 7 -> 12, 8 -> 12}, Left, VertexShapeFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2], Black, Text[#2, #1]}&)]流程图
LayeredGraphPlot 帮助可视化流程图,例如应用在商业、经济或技术演讲中.
LayeredGraphPlot[{"total" -> "TotalDispatch", "TotalList" -> "CheckThreading", "TotalList" -> "TotalDispatch", "TotalSparse" -> "TotalDispatch", "TotalSparse" -> "TotalDispatch", "TotalDispatch" -> "TotalDispatch", "TotalDispatch" -> "TotalList", "TotalDispatch" -> "TotalPacked", "TotalDispatch" -> "TotalSparse"}, VertexLabels -> Automatic]LayeredGraphPlot[{"ratiotest" -> "ratiolimit", "getdata" -> "dir_inf _bad", "getdata" -> "evalderiv", "NSPpreliminaries" -> "getdata", "findsp" -> "termlimit", "findsp" -> "ratiotest", "findsp" -> "nSumW", "findsp" -> "nSumEM", "findsp" -> "nProductEM", "findsp" -> "nProductW", "nSumW" -> "nSumFinite", "nSumW" -> "nSumWtail", "nSumEM" -> "evalterm", "nSumEM" -> "nSumFinite", "nSumEM" -> "evalderiv", "nProductEM" -> "nPFinite", "nProductW" -> "nPFinite", "nProductW" -> "nPWtail", "oNSum" -> "CleanOptionList", "oNSum" -> "multidim", "oNSum" -> "NSPpreliminaries", "oNSum" -> "findsp", "nSumFinite" -> "evalterm", "nSumWtail" -> "evalterm", "nSumWtail" -> "epsalg", "oNProduct" -> "CleanOptionList", "oNProduct" -> "multidim", "oNProduct" -> "NSPpreliminaries", "oNProduct" -> "findsp", "nPFinite" -> "evalterm", "nPWtail" -> "evalterm", "nPWtail" -> "epsalg", "oSequenceLimit" -> "epsalg"}, Left, VertexLabels -> Automatic, AspectRatio -> 1, PlotRangePadding -> 0.02]食物链
使用 LayeredGraphPlot 可视化食物链.
LayeredGraphPlot[{"John" -> "plants",
"lion" -> "John", "tiger" -> "John", "tiger" -> "deer", "lion" -> "deer", "deer" -> "plants",
"mosquito" -> "lion", "frog" -> "mosquito", "mosquito" -> "tiger", "John" -> "cow", "cow" -> "plants", "mosquito" -> "deer", "mosquito" -> "John", "snake" -> "frog", "vulture" -> "snake"}, Left,
VertexLabels -> Automatic]LayeredGraphPlot[ {"Raccoon" -> "Bird", "Raccoon" -> "Insect", "Wildcat" -> "Bird", "Wildcat" -> "Rodent", "Fox" -> "Bird", "Fox" -> "Garter snake", "Fox" -> "Salamander", "Fox" -> "Rabbit", "Fox" -> "Rodent", "Wolf" -> "Rabbit", "Wolf" -> "Rodent", "Wolf" -> "Skunk", "Wolf" -> "Deer", "Bear" -> "Deer", "Bear" -> "Rodent", "Bear" -> "Plant", "Bird" -> "Plant", "Garter snake" -> "Insect", "Garter snake" -> "Toad", "Salamander" -> "Insect", "Rabbit" -> "Plant", "Skunk" -> "Rodent", "Skunk" -> "Insect", "Deer" -> "Plant", "Toad" -> "Insect", "Insect" -> "Plant"}, VertexLabels -> Automatic, PlotRangePadding -> Automatic]Unix 的历史
LayeredGraphPlot 适用于可视化历史事件.
LayeredGraphPlot[{"5th Edition" -> "6th Edition", "5th Edition" -> "PWB 1.0",
"6th Edition" -> "1 BSD", "6th Edition" -> "Interdata",
"6th Edition" -> "LSX", "6th Edition" -> "Mini Unix",
"6th Edition" -> "Wollongong", "PWB 1.0" -> "PWB 1.2",
"PWB 1.0" -> "USG 1.0", "1 BSD" -> "2 BSD", "Interdata" -> "PWB 2.0",
"Interdata" -> "Unix/TS 3.0", "Interdata" -> "7th Edition",
"PWB 1.2" -> "PWB 2.0", "USG 1.0" -> "USG 2.0", "USG 1.0" -> "CB Unix 1",
"7th Edition" -> "2 BSD", "7th Edition" -> "32V", "7th Edition" -> "Xenix",
"7th Edition" -> "Ultrix-11", "7th Edition" -> "UniPlus+",
"7th Edition" -> "V7M", "PWB 2.0" -> "Unix/TS 3.0", "USG 2.0" -> "USG 3.0",
"CB Unix 1" -> "CB Unix 2", "32V" -> "3 BSD",
"Unix/TS 1.0" -> "Unix/TS 3.0", "USG 3.0" -> "Unix/TS 3.0",
"CB Unix 2" -> "CB Unix 3", "3 BSD" -> "4 BSD", "V7M" -> "Ultrix-11",
"Unix/TS 3.0" -> "TS 4.0", "CB Unix 3" -> "Unix/TS++",
"CB Unix 3" -> "PDP-11 Sys V", "4 BSD" -> "4.1 BSD",
"Unix/TS++" -> "TS 4.0", "4.1 BSD" -> "8th Edition", "4.1 BSD" -> "4.2 BSD",
"4.1 BSD" -> "2.8 BSD", "2 BSD" -> "2.8 BSD", "TS 4.0" -> "System V.0",
"4.2 BSD" -> "4.3 BSD", "4.2 BSD" -> "Ultrix-32", "2.8 BSD" -> "2.9 BSD",
"2.8 BSD" -> "Ultrix-11", "System V.0" -> "System V.2",
"8th Edition" -> "9th Edition", "System V.2" -> "System V.3"}, VertexLabels -> Automatic, AspectRatio -> 0.7, PlotRangePadding -> Automatic]相关技术笔记
-
▪
- 绘图