ExpressionGraph[expr]
给出树状图,显示不同的深度处不同的层级.
ExpressionGraph[expr,n]
只给出到层级 n 的树状图.
ExpressionGraph[expr,n,form]
给出树状图,其中,与 form 匹配的子表达式为叶子.
ExpressionGraph
ExpressionGraph[expr]
给出树状图,显示不同的深度处不同的层级.
ExpressionGraph[expr,n]
只给出到层级 n 的树状图.
ExpressionGraph[expr,n,form]
给出树状图,其中,与 form 匹配的子表达式为叶子.
更多信息和选项
- ExpressionGraph 生成 Graph 对象.
- ExpressionGraph 通常用来根据 Wolfram 语言表达式生成表达式树.
- ExpressionGraph[expr] 给出顶点为 {1,2,…} 的树状图,每个顶点都有 "Subexpression" 注释.
- ExpressionGraph 采用与 Graph 相同的部分选项,但有以下更改: [所有选项的列表]
-
FormatType StandardForm 用于顶点和边标签的格式类型
所有选项的列表
范例
打开所有单元 关闭所有单元基本范例 (3)
范围 (5)
ExpressionGraph 适用于格式化符号表达式:
ExpressionGraph[E^n I π]ExpressionGraph 适用于含有有下标的变量的表达式:
ExpressionGraph[Subscript[x, 1] + Subscript[x, 2]]ExpressionGraph[{1, {2, {3}}}]ExpressionGraph[[image]]ExpressionGraph[{1, {2, {3}}}, 2]用 VertexLabels->Automatic 生成有标签的图:
ExpressionGraph[a + b ^ Cos[e + 1] + c ^ 3 + d + Cos[e], VertexLabels -> Automatic]ExpressionGraph[a + b ^ Cos[e + 1] + c ^ 3 + d + Cos[e], _Cos, VertexLabels -> Automatic]选项 (82)
AnnotationRules (3)
ExpressionGraph[a + b + c, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]ExpressionGraph[a + b + c, AnnotationRules -> {12 -> {EdgeLabels -> "hello"}}]ExpressionGraph[a + b + c, AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]AnnotationValue[%, "Message"]DirectedEdges (1)
ExpressionGraph[a + b + c]用 DirectedEdges->True 生成有向图:
ExpressionGraph[a + b + c, DirectedEdges -> True]EdgeLabels (7)
ExpressionGraph[a + b, EdgeLabels -> {12 -> "Hello"}]el = EdgeList[ExpressionGraph[a + b]]ExpressionGraph[a + b, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]ExpressionGraph[a + b ^ 2, EdgeLabels -> {12 -> [image], 13 -> [image], 34 -> [image]}]将 Placed 与符号位置一起使用,以控制在边的什么位置放置标签:
Table[ExpressionGraph[a + b, EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[ExpressionGraph[a + b, EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Table[ExpressionGraph[a + b, EdgeLabels -> {12 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]ExpressionGraph[a + b + c, EdgeLabels -> {12 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]ExpressionGraph[a + b + c, EdgeLabels -> {12 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]通过 Tooltip 和 StatusArea 用值进行自动标注:
ExpressionGraph[a + b + c, EdgeLabels -> Placed["Name", Tooltip]]ExpressionGraph[a + b + c, EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
获取 EdgeShapeFunction 的内置设置列表:
ResourceData["EdgeShapeFunction"]ExpressionGraph[a + b + c, EdgeShapeFunction -> "Line"]Table[ExpressionGraph[a + b + c, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[ExpressionGraph[a + b + c, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[ExpressionGraph[a + b + c, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[ExpressionGraph[a + b + c, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]ExpressionGraph[a + b + c, EdgeShapeFunction -> {12 -> "DotLine"}]ExpressionGraph[a + b + c, EdgeShapeFunction -> {12 -> "BoxLine", "DotLine"}]ef[pts_List, e_] :=
Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]ExpressionGraph[a + b + c, EdgeShapeFunction -> ef]EdgeShapeFunction 可与 EdgeStyle 组合使用:
ExpressionGraph[a + b + c, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunction 比 EdgeStyle 的优先级高:
ExpressionGraph[a + b + c, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
EdgeWeight (3)
ExpressionGraph[a + b + c, EdgeWeight -> RandomInteger[5, 2]]WeightedAdjacencyMatrix[%]//MatrixFormExpressionGraph[a + b + c, EdgeWeight -> {a, b}]WeightedAdjacencyMatrix[%]//MatrixFormExpressionGraph[a + b + c, EdgeWeight -> {12 -> 2, 13 -> 4}]AnnotationValue[{%, 12}, EdgeWeight]GraphHighlight (3)
ExpressionGraph[a + b + c, VertexSize -> Tiny, GraphHighlight -> {1}]ExpressionGraph[a + b + c, VertexSize -> Tiny, GraphHighlight -> {13}]ExpressionGraph[a + b + 1, VertexSize -> Tiny, GraphHighlight -> {1, 2, 12, 13}]GraphHighlightStyle (2)
获取 GraphHighlightStyle 的内置设置的列表:
ResourceData["GraphHighlightStyle"]使用 GraphHighlightStyle 的内置设置:
ExpressionGraph[a + b + c, GraphHighlight -> {1, 13}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
ExpressionGraph[a + b + c, GraphLayout -> Automatic]Table[ExpressionGraph[a + b ^ 2, GraphLayout -> l, PlotLabel -> Style[l, 10]], {l, {"CircularEmbedding", "SpiralEmbedding"}}]Table[ExpressionGraph[a + b ^ 2 + c ^ 3 + d, GraphLayout -> l, PlotLabel -> Style[l, 10]], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinates 将覆盖 GraphLayout 的坐标:
{ExpressionGraph[a + b + c, GraphLayout -> "SpringElectricalEmbedding"],
ExpressionGraph[a + b + c, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 3}]]}用 AbsoluteOptions 提取用布局算法得出的 VertexCoordinates:
ExpressionGraph[a + b + c]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本主题 (2)
VertexCoordinates (2)
ExpressionGraph[a + b + c]用 AbsoluteOptions 提取所得的顶点坐标:
AbsoluteOptions[%, VertexCoordinates]ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]Graphics[Point[ellipseLayout[29, {2, 1}]]]ExpressionGraph[a + b ^ 2 + c ^ 3 + d, VertexCoordinates -> ellipseLayout[9, {2, 1}]]VertexLabels (13)
ExpressionGraph[a + b + c, VertexLabels -> "Name"]ExpressionGraph[a + b + c, VertexLabels -> {1 -> "one"}]ExpressionGraph[a + b + c, VertexLabels -> Table[i -> Subscript[v, i], {i, 3}]]ExpressionGraph[a + b + c, VertexLabels -> {1 -> **[image]**, 2 -> [image], 3 -> [image]}]将 Placed 与符号式位置合用,控制标签的放置,包括顶点外的位置:
Table[ExpressionGraph[a + b + c, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};Table[ExpressionGraph[a + b + c, VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[ExpressionGraph[a + b + c, VertexSize -> 0.25, VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};Table[ExpressionGraph[a + b + c, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[ExpressionGraph[a + b + c, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 4}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]Table[ExpressionGraph[a + b + c, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], {{1, 1}, p}], {i, 4}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]ExpressionGraph[a + b + c, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]ExpressionGraph[a + b + c, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]ExpressionGraph[a + b + c, VertexLabels -> Placed["Name", Tooltip]]或 StatusArea:
ExpressionGraph[a + b + c, VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]ExpressionGraph[a + b + c, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 4}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]ExpressionGraph[a + b + c, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 4}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]ExpressionGraph[a + b + c, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 4}]]VertexShape (5)
使用任意 Graphics、Image 或 Graphics3D 作为顶点的形状:
Table[ExpressionGraph[a + b + c, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]ExpressionGraph[a + b + c, VertexShape -> {2 -> [image]}, VertexSize -> Small]VertexShape 可与 VertexSize 组合使用:
Table[ExpressionGraph[a + b + c, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]VertexShape 不受 VertexStyle 的影响:
ExpressionGraph[a + b + c, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunction 比 VertexShape 的优先级高:
ExpressionGraph[a + b + c, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
获取 VertexShapeFunction 的内置集合列表:
ResourceData["VertexShapeFunction"]使用 "Basic" 集合中 VertexShapeFunction 的内置设置:
ResourceData["VertexShapeFunction", "Basic"]Table[ExpressionGraph[a + b + c, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[ExpressionGraph[a + b + c, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]使用 "Rounded" 集合中 VertexShapeFunction 的内置设置:
ResourceData["VertexShapeFunction", "Rounded"]Table[ExpressionGraph[a + b + c, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]使用 "Concave" 集合中 VertexShapeFunction 的内置设置:
ResourceData["VertexShapeFunction", "Concave"]Table[ExpressionGraph[a + b + c, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]ExpressionGraph[a + b + c, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]ExpressionGraph[a + b + c, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]ExpressionGraph[a + b + c, 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}}]
];ExpressionGraph[a + b + c, VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunction 可与 VertexStyle 组合使用:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]ExpressionGraph[a + b + c, 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}]}ExpressionGraph[a + b + c, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunction 可与 VertexSize 组合使用:
ExpressionGraph[a + b + c, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunction 比 VertexShape 的优先级高:
ExpressionGraph[a + b + c, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
ExpressionGraph[a + b + c, VertexSize -> Automatic]Table[ExpressionGraph[a + b + c, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[ExpressionGraph[a + b + c, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[ExpressionGraph[a + b + c, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[ExpressionGraph[a + b + c, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]ExpressionGraph[a + b + c, VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSize 可与 VertexShapeFunction 组合使用:
Table[ExpressionGraph[a + b + c, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSize 可与 VertexShape 组合使用:
Table[ExpressionGraph[a + b + c, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VertexStyle (5)
Table[ExpressionGraph[a + b + c, VertexStyle -> style, VertexSize -> 0.3], {style, {Yellow, EdgeForm[Dashed]}}]ExpressionGraph[a + b + c, 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}]ExpressionGraph[a + b + c, 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}]}ExpressionGraph[a + b + c, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyle 可与 BaseStyle 组合使用:
ExpressionGraph[a + b + c, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyle 比 BaseStyle 的优先级高:
ExpressionGraph[a + b + c, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]VertexShape 不受 VertexStyle 的影响:
ExpressionGraph[a + b + c, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (3)
ExpressionGraph[a + b + c, VertexWeight -> {2, 3, 4, 5}]AnnotationValue[{%, 1}, VertexWeight]ExpressionGraph[a + b + c, VertexWeight -> {1 -> 2}]AnnotationValue[{%, 1}, VertexWeight]ExpressionGraph[a + b + c, VertexWeight -> {a, b, c, d}]AnnotationValue[{%, 1}, VertexWeight]应用 (2)
属性和关系 (5)
用 VertexCount 和 EdgeCount 计算顶点数和边数:
g = ExpressionGraph[a + b ^ 2 + c]{VertexCount[g], EdgeCount[g]}用 VertexList 和 EdgeList 以标准顺序列出顶点和边:
g = ExpressionGraph[a + b ^ 2 + c]{VertexList[g], EdgeList[g]}从一个图计算 AdjacencyMatrix:
g = ExpressionGraph[Rectangle[]]AdjacencyMatrix[g]//MatrixFormFullForm 给出与 ExpressionGraph 类似的线性表达式:
FullForm[1 / (a + b) * x ^ 2]ExpressionGraph[1 / (a + b) * x ^ 2, VertexLabels -> Automatic]用 TreeForm 绘制树状图:
TreeForm[1 / (a + b) * x ^ 2]可能存在的问题 (1)
ExpressionGraph[expr] 可用于对表达式 expr 进行计算:
ExpressionGraph[1 + 1, VertexLabels -> Automatic]ExpressionGraph[Unevaluated[1 + 1], VertexLabels -> Automatic]相关指南
-
▪
- 图的构建与表示
文本
Wolfram Research (2020),ExpressionGraph,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ExpressionGraph.html.
CMS
Wolfram 语言. 2020. "ExpressionGraph." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ExpressionGraph.html.
APA
Wolfram 语言. (2020). ExpressionGraph. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ExpressionGraph.html 年
BibTeX
@misc{reference.wolfram_2026_expressiongraph, author="Wolfram Research", title="{ExpressionGraph}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ExpressionGraph.html}", note=[Accessed: 08-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_expressiongraph, organization={Wolfram Research}, title={ExpressionGraph}, year={2020}, url={https://reference.wolfram.com/language/ref/ExpressionGraph.html}, note=[Accessed: 08-September-2026]}