TreeGraph
詳細とオプション
- TreeGraphはGraphオブジェクトを生成する.
- TreeGraphはGraphと同じ頂点,辺,ラッパー,オプションをサポートする.
- 木は巡回のない単純な連結グラフである.
- 木は巡回しない連結グラフである.
- TreeGraphは木しか表さない.
全オプションのリスト
例題
すべて開く すべて閉じる例 (1)
スコープ (25)
接続性 (6)
記号 を使って無向グラフを作る.この記号は
ue
で入力する:
TreeGraph[{12, 13, 14}]記号 を使って有向グラフを作る.この記号は
de
で入力する:
TreeGraph[{12, 13, 14}]TreeGraph[{1 -> 2, 1 -> 3, 1 -> 4}]TreeGraph[{1 -> 2, 1 -> 3, 1 -> 4}, DirectedEdges -> False]VertexListとEdgeListを使って辺と頂点を得る:
{g1, g2} = {TreeGraph[{12, 13, 14}], TreeGraph[{13, 12, 14}]}EdgeList /@ {g1, g2}VertexList /@ {g1, g2}明示的な頂点のリストを使ってVertexListで使われる順序を制御する:
{g1, g2} = {TreeGraph[{1, 2, 3, 4}, {13, 12, 14}], TreeGraph[{3, 2, 1, 4}, {13, 12, 14}]}VertexList /@ {g1, g2}{TreeGraph[{ab, ac}], TreeGraph[{"foo""bar", "foo""gnu"}],
TreeGraph[{[image][image], [image][image]}]}VertexList /@ %ラッパー (5)
{TreeGraph[{Style[1, Red], 2, 3, 4}, {12, 13, 14}], TreeGraph[{1, 2, 3, 4}, {Style[12, Red], 13, 14}]}{TreeGraph[{Labeled[Style[1, Red], "hello"], 2, 3, 4}, {12, 13, 14}], TreeGraph[{1, 2, 3, 4}, {Style[Labeled[12, "hello"], Red], 13, 14}]}Tooltipのようなラッパーでインタラクティブな動作を加える:
TreeGraph[{12, 13, Tooltip[Style[14, Red], "hello"]}]TreeGraph[{12, 13, Tooltip[Style[14, Red], Plot[Sin[x], {x, 0, 2Pi}]]}]Buttonを使って辺や頂点がクリックされたときにアクションが起るようにする:
{TreeGraph[{12, Button[Style[13, Red], Speak["Edge from 1 to 3"]]}], TreeGraph[{1, 2, Button[Style[3, Red], Speak["Vertex 3"]]}, {12, 23}, VertexSize -> Medium]}PopupWindowを使ってドリルダウン情報を加える:
TreeGraph[{12, 13, PopupWindow[Style[14, Red], DateListPlot[FinancialData["IBM", "Jan. 1, 2004"]]]}]スタイル付け (8)
{TreeGraph[{12, 13, 14}, VertexStyle -> Green], TreeGraph[{12, 13, 14}, EdgeStyle -> Green]}{TreeGraph[{12, 13, 14}, VertexStyle -> {1 -> Green, Orange}], TreeGraph[{12, 13, 14}, EdgeStyle -> {12 -> Green, Orange}]}{TreeGraph[{Style[1, Green], 2, 3}, {12, 13, 14}, VertexStyle -> Orange], TreeGraph[{Style[12, Green], 13, 14}, EdgeStyle -> Orange]}Table[TreeGraph[{12, 13, 14}, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[TreeGraph[{12, 13, 14}, VertexSize -> s, PlotLabel -> s], {s, {0.1, 0.2, 0.5, 1}}]VertexShapeFunctionの組込みコレクションを使う:
Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> s, VertexSize -> 0.2, PlotLabel -> s], {s, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> s, VertexSize -> 0.2, PlotLabel -> s], {s, ResourceData["VertexShapeFunction", "Rounded"]}]Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> s, VertexSize -> 0.2, PlotLabel -> s], {s, ResourceData["VertexShapeFunction", "Concave"]}]TreeGraph[{12, 13, 14}, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]TreeGraph[{12, 13, 14}, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]任意のGraphics,ImageあるいはGraphics3Dを頂点の形として使う:
Table[TreeGraph[{12, 13, 14}, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]EdgeShapeFunctionの組込みコレクションを使う:
Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {12 -> "UnfilledArrow"}]TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {12 -> "FilledArrow", "CarvedArrow"}]ラベル付け (6)
{TreeGraph[{Labeled[12, "hello"], 13, 14}], TreeGraph[{Labeled[1, "hello"], 2, 3}, {12, 13, 14}]}Table[TreeGraph[{1, 2, Labeled[3, l]}, {12, 13, 14}], {l, {Sin[x], [image], [image]}}]Table[TreeGraph[{12, 13, Labeled[14, l]}], {l, {Sin[x], [image], [image]}}]Placedを使って記号的な内側の位置を含む頂点ラベルの置き方を制御する:
Table[TreeGraph[{1, 2, Labeled[3, Placed["■■", p]]}, {12, 23}, PlotLabel -> p, VertexSize -> 0.25, VertexShapeFunction -> "Square"], {p, {Left, Right, Top, Bottom}}]Table[TreeGraph[{1, 2, Labeled[3, Placed["■■", p]]}, {12, 23}, PlotLabel -> p, VertexSize -> Small, VertexShapeFunction -> "Square"], {p, {Before, After, Below, Above}}]Table[TreeGraph[{1, 2, Labeled[3, Placed["■", p]]}, {12, 13}, VertexSize -> 0.25, VertexShapeFunction -> "Square", PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]Placedをラッパーで使って複数のラベルを置く:
TreeGraph[{1, 2, 3, Labeled[4, Placed[{"lbl1", "lbl2"}, {Above, Below}]]}, {12, 13, 14}]TreeGraph[{1, 2, 3, Labeled[4, Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]]}, {12, 13, 14}]VertexLabelsを使って複数のラベルを置く:
TreeGraph[{12, 13, 14}, VertexLabels -> {4 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]Placedを記号位置と一緒に使って辺に沿ったラベルの置き方を制御する:
Table[TreeGraph[{Labeled[12, Placed["■■", p]], 13}, PlotLabel -> p, VertexSize -> Small], {p, {"Start", "Middle", "End"}}]Table[TreeGraph[{Labeled[12, Placed["■■", p]], 13}, PlotLabel -> p, VertexSize -> Small, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Placedをラッパーで使って複数のラベルを置く:
TreeGraph[{12, 13, Labeled[14, Placed[{"lbl1", "lbl2"}, {"Start", "End"}]]}]TreeGraph[{12, 13, Labeled[14, Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]]}]EdgeLabelsを使って複数のラベルを置く:
TreeGraph[{12, 13, 14}, EdgeLabels -> {14 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]オプション (82)
AnnotationRules (3)
TreeGraph[{12, 13, 14}, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]TreeGraph[{12, 13, 14}, AnnotationRules -> {12 -> {EdgeLabels -> "hello"}}]TreeGraph[{12, 13, 14}, AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]AnnotationValue[%, "Message"]DirectedEdges (2)
TreeGraph[{1 -> 2, 1 -> 3, 1 -> 4}, EdgeStyle -> Arrowheads[Medium], EdgeShapeFunction -> "Arrow"]DirectedEdges->Falseを使って規則を無向辺として解釈するようにする:
TreeGraph[{1 -> 2, 1 -> 3, 1 -> 4}, DirectedEdges -> False]DirectedEdgeあるいはUndirectedEdgeを使ってグラフが有向か無向かを直接指定する:
{TreeGraph[{12, 13, 14}, EdgeStyle -> Arrowheads[Medium], EdgeShapeFunction -> "Arrow"], TreeGraph[{12, 13, 14}]}EdgeLabels (7)
TreeGraph[{12, 13, 14}, EdgeLabels -> {12 -> "Hello"}]el = {12, 13, 14};TreeGraph[el, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]TreeGraph[{12, 13, 14}, EdgeLabels -> {12 -> [image], 13 -> [image], 14 -> [image]}]Placedを記号位置と一緒に使って辺に沿ったラベルの置き方を制御する:
Table[TreeGraph[{12, 13, 14}, EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[TreeGraph[{12, 13, 14}, EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 3, 1 / 4}}]Table[TreeGraph[{12, 13, 14}, EdgeLabels -> {12 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]Placedをラッパーで使って複数のラベルを置く:
TreeGraph[{12, 13, Labeled[14, Placed[{"lbl1", "lbl2"}, {"Start", "End"}]]}]TreeGraph[{12, 13, Labeled[14, Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]]}]EdgeLabelsを使って複数のラベルを置く:
TreeGraph[{12, 13, 14}, EdgeLabels -> {14 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]TooltipとStatusAreaからの値で自動的にラベルを付ける:
TreeGraph[{12, 13, 14}, EdgeLabels -> Placed["Name", Tooltip]]TreeGraph[{12, 13, 14}, EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
EdgeShapeFunctionの組込み設定のリストを得る:
ResourceData["EdgeShapeFunction"]TreeGraph[{12, 13, 14}, EdgeShapeFunction -> "Line"]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]TreeGraph[{12, 13, 14}, EdgeShapeFunction -> {12 -> "FilledArcArrow"}]TreeGraph[{12, 13, 14}, 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]}]TreeGraph[{12, 13, 14}, EdgeShapeFunction -> ef]EdgeShapeFunctionはEdgeStyleと組み合せることができる:
TreeGraph[{12, 13, 14}, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunctionはEdgeStyleより優先順位が高い:
TreeGraph[{12, 13, 14}, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
EdgeWeight (2)
TreeGraph[{12, 13, 14}, EdgeWeight -> RandomInteger[5, 3]]WeightedAdjacencyMatrix[%]//MatrixFormTreeGraph[{12, 13, 14}, EdgeWeight -> {a, b, c}]WeightedAdjacencyMatrix[%]//MatrixFormGraphHighlight (3)
TreeGraph[{12, 13, 14}, VertexSize -> Medium, GraphHighlight -> {1}]TreeGraph[{12, 13, 14}, VertexSize -> Tiny, GraphHighlight -> {13}]TreeGraph[{12, 13, 14}, VertexSize -> Tiny, GraphHighlight -> {1, 2, 12, 13}]GraphHighlightStyle (2)
GraphHighlightStyleの組込み設定のリストを得る:
ResourceData["GraphHighlightStyle"]GraphHighlightStyleの組込み設定を使う:
TreeGraph[{12, 13, 14}, GraphHighlight -> {1, 13}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
TreeGraph[{12, 13, 14}, GraphLayout -> Automatic]Table[TreeGraph[Table[ii + 1, {i, 20}], GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]el = EdgeList@CompleteKaryTree[4, 5];Table[TreeGraph[el, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinatesはGraphLayoutの座標を無効にする:
{TreeGraph[{12, 13, 14}, GraphLayout -> "SpringElectricalEmbedding"],
TreeGraph[{12, 13, 14}, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 3}]]}AbsoluteOptionsを使ってレイアウトアルゴリズムで計算されたVertexCoordinatesを抽出する:
TreeGraph[{12, 13, 14}]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本テーマ (2)
VertexCoordinates (3)
TreeGraph[{12, 13, 14}]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}]]]TreeGraph[Table[1i, {i, 2, 20}], VertexCoordinates -> ellipseLayout[20, {2, 1}]]VertexCoordinatesはGraphLayoutより優先順位が高い:
TreeGraph[{12, 13, 14}, VertexCoordinates -> Table[{i, i}, {i, 4}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
TreeGraph[{12, 13, 14}, VertexLabels -> "Name"]TreeGraph[{12, 13, 14}, VertexLabels -> {2 -> "one"}]TreeGraph[{12, 13, 14}, VertexLabels -> Table[i -> Subscript[v, i], {i, 4}]]TreeGraph[{12, 13}, VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 30]Placedを記号位置と一緒に使って外側位置を含むラベルの置き方を制御する:
Table[TreeGraph[{12, 13, 14}, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, {Before, After, Below, Above}}]pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};Table[TreeGraph[{12, 13, 14}, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[TreeGraph[{12, 13, 14}, 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[TreeGraph[{12, 13, 14}, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[TreeGraph[{12, 13, 14}, 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[TreeGraph[{12, 13, 14}, 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}}}]Placedをラッパーで使って複数のラベルを置く:
TreeGraph[{1, 2, 3, Labeled[4, Placed[{"lbl1", "lbl2"}, {Above, Below}]]}, {12, 13, 14}]TreeGraph[{1, 2, 3, Labeled[4, Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]]}, {12, 13, 14}]VertexLabelsを使って複数のラベルを置く:
TreeGraph[{12, 13, 14}, VertexLabels -> {4 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]Placedの引数を使ってTooltipを含むフォーマットを制御する:
TreeGraph[{12, 13, 14}, VertexLabels -> Placed["Name", Tooltip]]あるいはStatusAreaを含むフォーマットを制御する:
TreeGraph[{12, 13, 14}, VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]TreeGraph[{12, 13, 14}, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 4}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]TreeGraph[{12, 13, 14}, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 4}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]TreeGraph[{12, 13, 14}, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 4}]]VertexShape (5)
Graphics,ImageあるいはGraphics3Dを頂点の形に使う:
Table[TreeGraph[{12, 13, 14}, VertexShape -> s, VertexSize -> 0.3], {s, {[image], [image], [image]}}]TreeGraph[{12, 13, 14}, VertexShape -> {2 -> [image]}, VertexSize -> 0.3]VertexShapeはVertexSizeと組み合せることができる:
Table[TreeGraph[{12, 13, 14}, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Medium, Large}}]VertexShapeはVertexStyleの影響を受けない:
TreeGraph[{12, 13, 14}, VertexSize -> 0.3, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunctionはVertexShapeより優先順位が高い:
TreeGraph[{12, 13, 14}, VertexSize -> 0.2, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
組込みのVertexShapeFunctionコレクションのリストを得る:
ResourceData["VertexShapeFunction"]"Basic"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Basic"]Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]"Rounded"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Rounded"]Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]"Concave"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Concave"]Table[TreeGraph[{12, 13, 14}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]TreeGraph[{12, 13, 14}, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]TreeGraph[{12, 13, 14}, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]TreeGraph[{12, 13, 14}, 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}}]
];TreeGraph[{12, 13, 14}, VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]TreeGraph[{12, 13, 14}, 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}]}TreeGraph[{12, 13, 14}, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunctionはVertexSizeと組み合せることができる:
TreeGraph[{12, 13, 14}, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunctionはVertexShapeより優先順位が高い:
TreeGraph[{12, 13, 14}, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
TreeGraph[{12, 13, 14}, VertexSize -> Automatic]Table[TreeGraph[{12, 13, 14}, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[TreeGraph[{12, 13, 14}, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[TreeGraph[{12, 13, 14}, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[TreeGraph[{12, 13, 14}, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]TreeGraph[{12, 13, 14}, VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSizeはVertexShapeFunctionと組み合せることができる:
Table[TreeGraph[{12, 13, 14}, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSizeはVertexShapeと組み合せることができる:
Table[TreeGraph[{12, 13, 14}, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VertexStyle (5)
Table[TreeGraph[{12, 13, 14}, VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]TreeGraph[{12, 13, 14}, 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}]TreeGraph[{12, 13, 14}, 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}]}TreeGraph[{12, 13, 14}, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyleはBaseStyleと組み合せることができる:
TreeGraph[{12, 13, 14}, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyleはBaseStyleより優先順位が高い:
TreeGraph[{12, 13, 14}, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]VertexShapeはVertexStyleの影響を受けない:
TreeGraph[{12, 13, 14}, VertexSize -> 0.3, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (2)
TreeGraph[{12, 13, 14}, VertexWeight -> {2, 3, 4, 5}]AnnotationValue[{%, 1}, VertexWeight]TreeGraph[{12, 13, 14}, VertexWeight -> {a, b, c, d}]AnnotationValue[{%, 1}, VertexWeight]アプリケーション (4)
g = TreeGraph[RandomInteger[#] # + 1 & /@ Range[0, 30], VertexSize -> 0.4]GraphCenterとGraphPeripheryをハイライトする:
{HighlightGraph[g, GraphCenter[g]], HighlightGraph[g, GraphPeriphery[g]]}g = TreeGraph[RandomInteger[#] # + 1 & /@ Range[0, 30], VertexSize -> 0.4];VertexEccentricity[g, #]& /@ Range[3]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, FindVertexEccentricityPath[g, u]], {u, Range[3]}]g = TreeGraph[RandomInteger[#] # + 1 & /@ Range[0, 30], VertexSize -> 0.4];GraphRadius[g]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]]]HighlightGraph[g, FindRadiusPath[g]]g = TreeGraph[RandomInteger[#] # + 1 & /@ Range[0, 30], VertexSize -> 0.4];GraphDiameter[g]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]]]HighlightGraph[g, FindDiameterPath[g]]特性と関係 (9)
VertexCountとEdgeCountを使って辺と頂点を数える:
g = CompleteKaryTree[3, 3]{VertexCount[g], EdgeCount[g]}VertexListとEdgeListを使って頂点と辺を標準的な順序で列挙する:
g = TreeGraph[{12, 13, 34}];{VertexList[g], EdgeList[g]}g1 = TreeGraph[{34, 12, 13}];{VertexList[g1], EdgeList[g1]}グラフからAdjacencyMatrixを計算する:
g = TreeGraph[{12, 13, 1 -> 4}, EdgeStyle -> Arrowheads[Medium], EdgeShapeFunction -> "Arrow"](a = AdjacencyMatrix[g]//Normal)//MatrixFormCompleteKaryTree[3, 3]{ConnectedGraphQ[%], TreeGraphQ[%]}TreeGraph[Range[8], {1, 1, 2, 1, 4, 2, 3, 1}]{LoopFreeGraphQ[%], AcyclicGraphQ[%], TreeGraphQ[%]}TreeGraph[{1 -> 2, 1 -> 3, 2 -> 4, 2 -> 5, 3 -> 6}]VertexCount[%] - EdgeCount[%]CompleteKaryTree[3, 3]{ TreeGraphQ[%], BipartiteGraphQ[%]}
である
個の頂点を持つ木グラフには少なくとも2個,最高で
個の次数1の頂点がある:
TreeGraph[{1 -> 2, 1 -> 3}]VertexDegree[%]CompleteKaryTree[2, 6]VertexDegree[%]StarGraph[10]TreeGraphQ[%]テキスト
Wolfram Research (2010), TreeGraph, Wolfram言語関数, https://reference.wolfram.com/language/ref/TreeGraph.html (2015年に更新).
CMS
Wolfram Language. 2010. "TreeGraph." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/TreeGraph.html.
APA
Wolfram Language. (2010). TreeGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeGraph.html
BibTeX
@misc{reference.wolfram_2026_treegraph, author="Wolfram Research", title="{TreeGraph}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/TreeGraph.html}", note=[Accessed: 30-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_treegraph, organization={Wolfram Research}, title={TreeGraph}, year={2015}, url={https://reference.wolfram.com/language/ref/TreeGraph.html}, note=[Accessed: 30-November-2026]}