-
参见
- 函 数
- AdjacencyMatrix
- WeightedAdjacencyGraph
- IncidenceGraph
- KirchhoffGraph
-
- 实体类型
- Graph
-
- 诠释器类型
- Graph
- 相关指南
-
-
参见
- 函 数
- AdjacencyMatrix
- WeightedAdjacencyGraph
- IncidenceGraph
- KirchhoffGraph
-
- 实体类型
- Graph
-
- 诠释器类型
- Graph
- 相关指南
-
参见
AdjacencyGraph[amat]
给出邻接矩阵为 amat 的图.
AdjacencyGraph[{v1,v2,…},amat]
给出顶点为 vi、邻接矩阵为 amat 的图.
AdjacencyGraph
AdjacencyGraph[amat]
给出邻接矩阵为 amat 的图.
AdjacencyGraph[{v1,v2,…},amat]
给出顶点为 vi、邻接矩阵为 amat 的图.
更多信息和选项
- AdjacencyGraph[amat] 等价于 AdjacencyGraph[{1,2,…,n},amat],其中 amat 维度为
×
. - AdjacencyGraph 采用与 Graph 相同的选项.
- 选项 DirectedEdges 可以用来控制是否构建一个无向图或者有向图.
- DirectedEdges 的下列选项可以用于 AdjacencyGraph 中:
-
Automatic 如果 amat 是对称的,则构建一个无向图 True 构建一个有向图 False 构建一个无向图
所有选项的列表
背景
- AdjacencyGraph 根据无向或有向图的邻接矩阵构建一个图. 邻接矩阵是一个方阵,其行和列对应于图的顶点而其中的元素 aij 是非负整数,标明的是从顶点 vi 到顶点 vj 的(有向)边的数目. 对角线元素不为零的邻接矩阵意味着图有自环.
- 选项 DirectedEdges(可能的值为 Automatic、True 或 False)可被用于控制构建的是无向还是有向图. 默认情况下,若输入矩阵是对称的,则 AdjacencyGraph 返回无向图,否则返回有向图.
- AdjacencyGraph 与 Graph 有相同的选项(例如 EdgeStyle、VertexStyle、EdgeLabels、VertexLabels、GraphLayout、VertexCoordinates 等等). AdjacencyGraph 并不考虑图的权重,所以要从加权邻接矩阵构建图的话必须使用 WeightedAdjacencyGraph.
- AdjacencyList 返回给定顶点 vi 的相邻顶点的列表并因此对应于邻接矩阵第 i
列(若是无向图则是第 i
行)非零元素的位置列表. 任何图的整个邻接矩阵(包括用 AdjacencyGraph 构建的)都可以用 AdjacencyMatrix 返回得到. IncidenceGraph 用关联矩阵表示代替邻接矩阵来构造图.
范例
打开所有单元 关闭所有单元基本范例 (2)
范围 (7)
AdjacencyGraph[(| | | | |
| - | - | - | - |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)]AdjacencyGraph[(| | | | |
| - | - | - | - |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 |)]利用 DirectedEdges 从对称矩阵创建有向图:
AdjacencyGraph[(| | | | |
| - | - | - | - |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |), DirectedEdges -> True]{AdjacencyGraph[(| | | | |
| - | - | - | - |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)], AdjacencyGraph[(| | | | |
| - | - | - | - |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 |)]}利用一个 SparseArray 对象指定邻接矩阵:
AdjacencyGraph[SparseArray[{{i_, j_} /; 0 < Abs[i - j] ≤ 3 -> 1}, {6, 6}]]VertexList@AdjacencyGraph[(| | | | |
| - | - | - | - |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)]VertexList@AdjacencyGraph[{a, b, c, d}, (| | | | |
| - | - | - | - |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)]AdjacencyGraph 可用于大规模矩阵:
SparseArray[{Band[{2, 1}] -> 1, Band[{3, 1}] -> 1}, {10^6, 10^6}]Timing[AdjacencyGraph[%]//EdgeCount]选项 (83)
AnnotationRules (3)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), AnnotationRules -> {3 -> {VertexLabels -> "hello"}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), AnnotationRules -> {12 -> {EdgeLabels -> "hello"}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]AnnotationValue[%, "Message"]DirectedEdges (3)
AdjacencyGraph[(| | | | | |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |)]使用 DirectedEdges->True 来生成一个有向图:
AdjacencyGraph[(| | | | | |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |), DirectedEdges -> True, EdgeStyle -> Arrowheads[Medium]]AdjacencyGraph[(| | | | | |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |)]EdgeLabels (7)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {12 -> "Hello"}]el = {12, 13, 23};AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {12 -> [image], 23 -> [image], 13 -> [image]}]使用符号位置信息的 Placed 来控制沿着一条边的标签位置:
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {12 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {31 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {31 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]通过 Tooltip 和 StatusArea 的值,使用自动标签:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> Placed["Name", Tooltip]]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
获取 EdgeShapeFunction 的内置设置列表:
ResourceData["EdgeShapeFunction"]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeShapeFunction -> "Line"]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {12 -> "FilledArcArrow"}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {12 -> "FilledArcArrow", "CarvedArrow"}]ef[pts_List, e_] :=
Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeShapeFunction -> ef]EdgeShapeFunction 可以与 EdgeStyle 合起来使用:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunction 具有比 EdgeStyle 更高的优先级:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> style, PlotLabel -> style], {style, {Gray, Dashed, Thick}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> {12 -> Blue, 13 -> Dashed}]EdgeWeight (2)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeWeight -> RandomInteger[5, 3]]WeightedAdjacencyMatrix[%]//MatrixFormAdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeWeight -> {a, b, c}]WeightedAdjacencyMatrix[%]//MatrixFormGraphHighlight (3)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Tiny, GraphHighlight -> {1}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Tiny, GraphHighlight -> {23}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Tiny, GraphHighlight -> {1, 2, 23}]GraphHighlightStyle (2)
获取 GraphHighlightStyle 的内置设置列表:
ResourceData["GraphHighlightStyle"]使用 GraphHighlightStyle 的内置设置:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphHighlight -> {1, 23}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphLayout -> Automatic]m = AdjacencyMatrix[GridGraph[{10, 10}]];Table[AdjacencyGraph[m, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]m = AdjacencyMatrix[GridGraph[{10, 10}]];Table[AdjacencyGraph[m, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinates 重载 GraphLayout 坐标:
{AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphLayout -> "SpringElectricalEmbedding"],
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 2}]]}通过一个布局算法,利用 AbsoluteOptions 提取计算所得的 VertexCoordinates:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |)]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
Base Themes (2)
Feature Themes (2)
VertexCoordinates (3)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |)]使用 AbsoluteOptions 提取所得的顶点坐标:
AbsoluteOptions[%, VertexCoordinates]ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]Graphics[Point[ellipseLayout[20, {2, 1}]]]m = AdjacencyMatrix[PathGraph[Range[20]]];AdjacencyGraph[m, VertexCoordinates -> ellipseLayout[20, {2, 1}]]VertexCoordinates 具有比 GraphLayout 更高的优先级:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexCoordinates -> Table[{i, i}, {i, 3}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> "Name"]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {1 -> "one"}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Subscript[v, i], {i, 3}]]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 30]使用具有符号位置信息的 Placed 来控制标签位置,包括内部位置:
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.25, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], {{1, 1}, p}], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {3 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {3 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Placed["Name", Tooltip]]或者 StatusArea:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 3}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Blue, 0.7]]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 3}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 3}]]VertexShape (5)
将任意 Graphics、Image 或者 Graphics3D 作为顶点形状使用:
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShape -> {2 -> [image]}, VertexSize -> Small]VertexShape 可以与 VertexSize 合起来使用:
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]VertexShape 不受 VertexStyle 影响:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunction 具有比 VertexShape 更高的优先级:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
获取 VertexShapeFunction 的内置设置列表:
ResourceData["VertexShapeFunction"]利用 VertexShapeFunction 在 "Basic" 集合中的内置设置:
ResourceData["VertexShapeFunction", "Basic"]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]使用 VertexShapeFunction 在 "Rounded" 集合中的内置设置:
ResourceData["VertexShapeFunction", "Rounded"]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]使用 VertexShapeFunction 在 "Concave" 集合中的内置设置:
ResourceData["VertexShapeFunction", "Concave"]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> (Inset[[image], #]&)]vf[{xc_, yc_}, name_, {w_, h_}] :=
Block[{xmin = xc - w, xmax = xc + w, ymin = yc - h, ymax = yc + h},
Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}]
];AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunction 可以与 VertexStyle 合起来使用:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunction 具有比 VertexStyle 更高的优先级:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunction 可以与 VertexSize 合起来使用:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunction 具有比 VertexShape 更高的优先级:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Automatic]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSize 可以与 VertexShapeFunction 合起来使用:
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSize 可以与 VertexShape 合起来使用:
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VertexStyle (5)
Table[AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> {1 -> Blue, 2 -> Red}, VertexSize -> 0.2]VertexShapeFunction 可以与 VertexStyle 合起来使用:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunction 具有比 VertexStyle 更高的优先级:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyle 可以与 BaseStyle 合起来使用:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyle 具有比 BaseStyle 更高的优先级:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]VertexShape 不受 VertexStyle 影响:
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (2)
AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexWeight -> {2, 3, 4}]AnnotationValue[{%, 1}, VertexWeight]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexWeight -> {a, b, c}]AnnotationValue[{%, 1}, VertexWeight]应用 (2)
从集合列表 s 构建一个图,其中顶点 i 表示 s〚i〛 并且具有一条边 ij 如果 s〚i〛⊆s〚j〛:
s = Subsets[{1, 2, 3}]AdjacencyGraph[s, Table[Boole@SubsetQ[s[[i]], s[[j]]], {i, Length[s]}, {j, Length[s]}], VertexLabels -> "Name"]从整数列表 s 构建一个图,其中 ij 如果 s〚i〛 整除 s〚j〛 (s〚i〛∣s〚j〛):
s = Divisors[24]AdjacencyGraph[s, Table[Boole@Divisible[s[[i]], s[[j]]], {i, Length[s]}, {j, Length[s]}], VertexLabels -> "Name"]属性和关系 (6)
使用 VertexCount 和 EdgeCount 计算顶点数和边数:
g = AdjacencyGraph[(| | | | | |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |)]{VertexCount[g], EdgeCount[g]}利用 VertexList 和 EdgeList 以标准顺序列出顶点和边:
g = AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |)]{VertexList[g], EdgeList[g]}计算一个图的 AdjacencyMatrix:
g = AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |)];AdjacencyMatrix[g]//MatrixFormCompleteGraph[5]AdjacencyGraph [AdjacencyMatrix[%]]AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |)]LoopFreeGraphQ[%]AdjacencyGraph[(| | | |
| - | - | - |
| 1 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |)]如果对于一个邻接矩阵,所有对角线外的元素都是1的话,该邻接矩阵所对应的图是一个完全图:
m = (| | | | | |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |);MatrixPlot[m]AdjacencyGraph[m]CompleteGraphQ[%]参见
AdjacencyMatrix WeightedAdjacencyGraph IncidenceGraph KirchhoffGraph
实体类型: Graph
诠释器类型: Graph
Function Repository: AdjacencyHypergraph
相关链接
文本
Wolfram Research (2010),AdjacencyGraph,Wolfram 语言函数,https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
CMS
Wolfram 语言. 2010. "AdjacencyGraph." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
APA
Wolfram 语言. (2010). AdjacencyGraph. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/AdjacencyGraph.html 年
BibTeX
@misc{reference.wolfram_2026_adjacencygraph, author="Wolfram Research", title="{AdjacencyGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/AdjacencyGraph.html}", note=[Accessed: 18-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_adjacencygraph, organization={Wolfram Research}, title={AdjacencyGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/AdjacencyGraph.html}, note=[Accessed: 18-August-2026]}