给出 n 阶蝶图.
ButterflyGraph[n,b]
给出以 b 为基、n 为阶数的蝶图.
ButterflyGraph
给出 n 阶蝶图.
ButterflyGraph[n,b]
给出以 b 为基、n 为阶数的蝶图.
更多信息和选项
- ButterflyGraph 又称蝴蝶结图或沙漏图.
- 对于正整数 n 和 b,ButterflyGraph 产生一个 Graph 对象.
- ButterflyGraph[n,b] 是具有 (n+1)bn 个顶点的图,其中顶点是 {w,i} 对,而 w 是长度为 n 的基数为 b 的字符串,而 i 是在从 0 到 n 范围内的整数. 对于每个 i,存在从 {w,i} 到 {
,i+1} 的一条边,其中 w 和
在所有位数上都相同,除了第 (i +1)
位可能不同. - ButterflyGraph[n] 等价于 ButterflyGraph[n,2].
- ButterflyGraph 采用与 Graph 相同的选项.
所有选项的列表
范例
打开所有单元 关闭所有单元基本范例 (2)
选项 (80)
AnnotationRules (2)
DirectedEdges (1)
ButterflyGraph[1]使用 DirectedEdges->True 来生成一个有向图:
ButterflyGraph[1, DirectedEdges -> True]EdgeLabels (7)
ButterflyGraph[1, EdgeLabels -> {14 -> "Hello"}]el = EdgeList[ButterflyGraph[1]]ButterflyGraph[1, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]ButterflyGraph[1, EdgeLabels -> {12 -> [image], 34 -> [image], 32 -> [image]}]使用符号位置信息的 Placed 来控制沿着一条边的标签位置:
Table[ButterflyGraph[1, EdgeLabels -> {34 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[ButterflyGraph[1, EdgeLabels -> {23 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Table[ButterflyGraph[1, EdgeLabels -> {23 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]ButterflyGraph[1, EdgeLabels -> {12 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]ButterflyGraph[1, EdgeLabels -> {12 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]通过 Tooltip 和 StatusArea 的值,使用自动标签:
ButterflyGraph[1, EdgeLabels -> Placed["Name", Tooltip]]ButterflyGraph[1, EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
获取 EdgeShapeFunction 的内置设置列表:
ResourceData["EdgeShapeFunction"]ButterflyGraph[1, EdgeShapeFunction -> "Line"]Table[ButterflyGraph[1, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[ButterflyGraph[1, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[ButterflyGraph[1, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[ButterflyGraph[1, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]ButterflyGraph[1, EdgeShapeFunction -> {12 -> "DotLine"}]ButterflyGraph[1, 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]}]ButterflyGraph[1, EdgeShapeFunction -> ef]EdgeShapeFunction 可以与 EdgeStyle 合起来使用:
ButterflyGraph[1, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunction 具有比 EdgeStyle 更高的优先级:
ButterflyGraph[1, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
EdgeWeight (2)
GraphHighlight (3)
GraphHighlightStyle (2)
获取 GraphHighlightStyle 的默认设置列表:
ResourceData["GraphHighlightStyle"]使用 GraphHighlightStyle 的内置设置列表:
ButterflyGraph[1, GraphHighlight -> {1, 12}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
ButterflyGraph[1, GraphLayout -> Automatic]Table[ButterflyGraph[3, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]Table[ButterflyGraph[3, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinates 覆写 GraphLayout 坐标:
{ButterflyGraph[1, GraphLayout -> "SpringElectricalEmbedding"],
ButterflyGraph[1, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 3}]]}通过一个布局算法,利用 AbsoluteOptions 提取计算所得的 VertexCoordinates:
ButterflyGraph[1]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本主题 (2)
VertexCoordinates (3)
ButterflyGraph[1]使用 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}]]]ButterflyGraph[2, VertexCoordinates -> ellipseLayout[12, {2, 1}]]VertexCoordinates 具有比 GraphLayout 更高的优先级:
ButterflyGraph[1, VertexCoordinates -> Table[{i, i}, {i, 4}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
ButterflyGraph[1, VertexLabels -> "Name"]ButterflyGraph[1, VertexLabels -> {2 -> "one"}]ButterflyGraph[1, VertexLabels -> Table[i -> Subscript[v, i], {i, 4}]]ButterflyGraph[1, VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 20]使用具有符号位置信息的 Placed 来控制标签位置,包括内部位置:
Table[ButterflyGraph[1, 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[ButterflyGraph[1, VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[ButterflyGraph[1, VertexSize -> 0.35, 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[ButterflyGraph[1, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[ButterflyGraph[1, 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[ButterflyGraph[1, 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}}}]ButterflyGraph[1, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]ButterflyGraph[1, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]使用 Placed 的变量来控制格式,包括 Tooltip:
ButterflyGraph[1, VertexLabels -> Placed["Name", Tooltip]]或者 StatusArea:
ButterflyGraph[1, VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]ButterflyGraph[1, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 4}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]ButterflyGraph[1, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 4}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]ButterflyGraph[1, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 4}]]VertexShape (5)
将任意 Graphics、Image 或者 Graphics3D 作为顶点形状使用:
Table[ButterflyGraph[1, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]ButterflyGraph[1, VertexShape -> {2 -> [image]}, VertexSize -> Medium]VertexShape 可以与 VertexSize 合起来使用:
Table[ButterflyGraph[1, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]VertexShape 不受 VertexStyle 影响:
ButterflyGraph[1, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunction 具有比 VertexShape 更高的优先级:
ButterflyGraph[1, VertexSize -> 0.2, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
获取 VertexShapeFunction 的内置设置列表:
ResourceData["VertexShapeFunction"]利用 VertexShapeFunction 在 "Basic" 集合中的内置设置:
ResourceData["VertexShapeFunction", "Basic"]Table[ButterflyGraph[1, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[ButterflyGraph[1, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]使用 VertexShapeFunction 在 "Rounded" 集合中的内置设置:
ResourceData["VertexShapeFunction", "Rounded"]Table[ButterflyGraph[1, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]使用 VertexShapeFunction 在 "Concave" 集合中的内置设置:
ResourceData["VertexShapeFunction", "Concave"]Table[ButterflyGraph[1, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]ButterflyGraph[1, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]ButterflyGraph[1, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]ButterflyGraph[1, 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}}]
];ButterflyGraph[1, VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunction 可以与 VertexStyle 合起来使用:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]ButterflyGraph[1, 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}]}ButterflyGraph[1, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunction 可以与 VertexSize 合起来使用:
ButterflyGraph[1, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunction 具有比 VertexShape 更高的优先级:
ButterflyGraph[1, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
ButterflyGraph[1, VertexSize -> Automatic]Table[ButterflyGraph[1, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[ButterflyGraph[1, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[ButterflyGraph[1, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[ButterflyGraph[1, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]ButterflyGraph[1, VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSize 可以与 VertexShapeFunction 合起来使用:
Table[ButterflyGraph[1, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSize 可以与 VertexShape 合起来使用:
Table[ButterflyGraph[1, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VertexStyle (5)
Table[ButterflyGraph[1, VertexStyle -> style, VertexSize -> 0.2, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]ButterflyGraph[1, 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}]ButterflyGraph[1, 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}]}ButterflyGraph[1, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyle 可以与 BaseStyle 合起来使用:
ButterflyGraph[1, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyle 具有比 BaseStyle 更高的优先级:
ButterflyGraph[1, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]VertexShape 不受 VertexStyle 影响:
ButterflyGraph[1, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (2)
应用 (6)
蝶图的 GraphCenter:
Table[HighlightGraph[#, GraphCenter[#]]&[ButterflyGraph[i, VertexSize -> Large]], {i, 1, 3}]Table[HighlightGraph[#, GraphPeriphery[#]]&[ButterflyGraph[i, VertexSize -> Large]], {i, 1, 3}]VertexEccentricity[ButterflyGraph[2, 2], #]& /@ VertexList[ButterflyGraph[2, 2]]FindVertexEccentricityPath[g_ ? UndirectedGraphQ, u_] /; MemberQ[VertexList[g], u] := Module[{d = GraphDistanceMatrix[g], posu, posv, vl = VertexList[g]}, posu = VertexIndex[g, u];
posv = First@First@Position[d[[posu]], Max[d[[posu]]]];
PathGraph[FindShortestPath[g, u, vl[[posv]]]]]Table[HighlightGraph[g = ButterflyGraph[2, 2], FindVertexEccentricityPath[g, u]], {u, Range[4]}]Table[GraphRadius[ButterflyGraph[i]], {i, 3}]FindRadiusPath[g_ ? UndirectedGraphQ] := Module[{c = First@GraphCenter[g], d, v, pos}, d = Table[GraphDistance[g, c, u], {u, VertexList[g]}];
pos = First@Position[d, Max[d]];
v = First@Part[VertexList[g], pos];
PathGraph[FindShortestPath[g, c, v]]]Table[HighlightGraph[#, FindRadiusPath[#]]&[ButterflyGraph[i, VertexSize -> Tiny]], {i, 3}]Table[GraphDiameter[ButterflyGraph[i]], {i, 3}]FindDiameterPath[g_ ? UndirectedGraphQ] := Module[{d = GraphDistanceMatrix[g], u, v, pos}, pos = First@Position[d, Max[d]];
{u, v} = Part[VertexList[g], pos];
PathGraph[FindShortestPath[g, u, v]]]Table[HighlightGraph[#, FindDiameterPath[#]]&[ButterflyGraph[i, VertexSize -> Tiny]], {i, 3}]突出显示 ButterflyGraph 的顶点度:
HighlightCentrality[g_, cc_] := HighlightGraph[g, Table[Style[VertexList[g][[i]], ColorData["TemperatureMap"][cc[[i]] / Max[cc]]], {i, VertexCount[g]}]];g = ButterflyGraph[2, VertexSize -> Large];HighlightCentrality[g, VertexDegree[g]]HighlightCentrality[g, ClosenessCentrality[g]]HighlightCentrality[g, EigenvectorCentrality[g]]属性和关系 (3)
ButterflyGraph[n,b] 具有
个顶点:
VertexCount[ButterflyGraph[n, b]]ButterflyGraph[n,b] 具有
条边:
EdgeCount[ButterflyGraph[n, b]]ButterflyGraph 是欧拉图:
ButterflyGraph[3]EulerianGraphQ[%]相关指南
-
▪
- 图的构建与表示
相关链接
文本
Wolfram Research (2010),ButterflyGraph,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ButterflyGraph.html.
CMS
Wolfram 语言. 2010. "ButterflyGraph." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ButterflyGraph.html.
APA
Wolfram 语言. (2010). ButterflyGraph. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ButterflyGraph.html 年
BibTeX
@misc{reference.wolfram_2026_butterflygraph, author="Wolfram Research", title="{ButterflyGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/ButterflyGraph.html}", note=[Accessed: 13-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_butterflygraph, organization={Wolfram Research}, title={ButterflyGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/ButterflyGraph.html}, note=[Accessed: 13-August-2026]}