PathGraph
詳細とオプション
- PathGraphはGraphオブジェクトを生成する.
- PathGraphはGraphと同じ頂点,辺,ラッパーおよびオプションをサポートする.
- 無向経路グラフは各頂点の次数が最高で2の連結グラフである.
- 有向経路グラフは各頂点の入次数および出次数が最高で1の連結グラフである.
- PathGraphは巡回以外では自己排除型の経路しか表すことができない.
全オプションのリスト
例題
すべて開く すべて閉じる例 (2)
スコープ (6)
連結性 (6)
PathGraph[{12, 23, 34}]PathGraph[{12, 23, 34}, EdgeStyle -> Arrowheads[Medium]]PathGraph[{1 -> 2, 2 -> 3, 3 -> 4}, EdgeStyle -> Arrowheads[Medium]]PathGraph[{1 -> 2, 2 -> 3, 3 -> 4}, DirectedEdges -> False]VertexListとEdgeListを使って頂点と辺を得る:
{g1, g2} = {PathGraph[{12, 23, 34}], PathGraph[{23, 12, 34}]}EdgeList /@ {g1, g2}VertexList /@ {g1, g2}明示的な頂点のリストを使ってVertexListで使われている順序を制御する:
{g1, g2} = {PathGraph[{1, 2, 3, 4}, {23, 12, 34}], PathGraph[{3, 2, 1, 4}, {23, 12, 34}]}VertexList /@ {g1, g2}{PathGraph[{ab, bc}], PathGraph[{"foo""bar", "bar""gnu"}],
PathGraph[{[image][image], [image][image]}]}VertexList /@ %オプション (82)
AnnotationRules (3)
PathGraph[Range[5], AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]PathGraph[Range[5], AnnotationRules -> {12 -> {EdgeLabels -> "hello"}}]PathGraph[Range[5], AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]AnnotationValue[%, "Message"]DirectedEdges (2)
PathGraph[{1 -> 2, 2 -> 3, 3 -> 4}, EdgeStyle -> Arrowheads[Medium]]DirectedEdges->Falseを使って規則を無向辺として解釈する:
PathGraph[{1 -> 2, 2 -> 3, 3 -> 4}, DirectedEdges -> False]DirectedEdgeまたはUndirectedEdgeを使って有向グラフであるかどうかを直接指定する:
{PathGraph[{12, 23, 34}, EdgeStyle -> Arrowheads[Medium]], PathGraph[{12, 23, 34}]}EdgeLabels (7)
PathGraph[Range[4], EdgeLabels -> {12 -> "Hello"}]el = {12, 23, 34};PathGraph[el, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]PathGraph[Range[4], EdgeLabels -> {12 -> [image], 23 -> [image], 34 -> [image]}]Placedを記号位置と一緒に使って辺に沿ったラベル配置を制御する:
Table[PathGraph[Range[4], EdgeLabels -> {23 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[PathGraph[Range[4], EdgeLabels -> {23 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 2, 1}}]Table[PathGraph[Range[4], EdgeLabels -> {23 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]Placedをラッパーに使って複数のラベルを置く:
PathGraph[{12, 23, Labeled[34, Placed[{"lbl1", "lbl2"}, {"Start", "End"}]]}]PathGraph[{12, 23, Labeled[34, Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]]}]EdgeLabelsを使って複数のラベルを置く:
PathGraph[{12, 23, 34}, EdgeLabels -> {34 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]TooltipとStatusAreaからの値で自動的にラベルを付ける:
PathGraph[Range[4], EdgeLabels -> Placed["Name", Tooltip]]PathGraph[Range[4], EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
EdgeShapeFunctionの組込み設定のリストを得る:
ResourceData["EdgeShapeFunction"]PathGraph[{12, 23, 34}, EdgeShapeFunction -> "Line"]Table[PathGraph[{12, 23, 34}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[PathGraph[{12, 23, 34}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[PathGraph[{12, 23, 34}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[PathGraph[{12, 23, 34}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]PathGraph[{12, 23, 34}, EdgeShapeFunction -> {12 -> "FilledArrow"}]PathGraph[{12, 23, 34}, 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]}]PathGraph[Range[4], EdgeShapeFunction -> ef]EdgeShapeFunctionはEdgeStyleと組み合せることができる:
PathGraph[Range[4], EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunctionはEdgeStyleより優先順位が高い:
PathGraph[Range[4], EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
EdgeWeight (2)
GraphHighlight (3)
PathGraph[Range[5], VertexSize -> Medium, GraphHighlight -> {1}]PathGraph[Range[5], VertexSize -> Tiny, GraphHighlight -> {23}]PathGraph[Range[5], VertexSize -> Tiny, GraphHighlight -> {1, 2, 12, 34}]GraphHighlightStyle (2)
GraphHighlightStyleの組込み設定のリストを得る:
ResourceData["GraphHighlightStyle"]GraphHighlightStyleの組込み設定を使う:
PathGraph[Range[20], GraphHighlight -> {1, 23}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
PathGraph[Range[10], GraphLayout -> Automatic]Table[PathGraph[Range[20], GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]Table[PathGraph[Range[20], GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinatesはGraphLayoutの座標を無効にする:
{PathGraph[{12, 23, 34}, GraphLayout -> "SpringElectricalEmbedding"],
PathGraph[{12, 23, 34}, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 3}]]}AbsoluteOptionsを使ってレイアウトアルゴリズムで計算されたVertexCoordinatesを抽出する:
PathGraph[{12, 23, 34}]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本テーマ (2)
VertexCoordinates (3)
PathGraph[Range[4]]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}]]]PathGraph[Range[20], VertexCoordinates -> ellipseLayout[20, {2, 1}]]VertexCoordinatesはGraphLayoutより優先順位が高い:
PathGraph[Range[4], VertexCoordinates -> Table[{i, i}, {i, 4}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
PathGraph[Range[4], VertexLabels -> "Name"]PathGraph[Range[4], VertexLabels -> {2 -> "one"}]PathGraph[Range[4], VertexLabels -> Table[i -> Subscript[v, i], {i, 4}]]PathGraph[Range[4], VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 20]Placedを記号位置と一緒に使って外側位置を含むラベルの置き方を制御する:
Table[PathGraph[Range[4], 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[PathGraph[Range[4], VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]Table[PathGraph[Range[3], VertexSize -> 0.5, 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[PathGraph[Range[3], VertexSize -> 0.5, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[PathGraph[Range[3], VertexSize -> 0.5, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]すべてのラベルを頂点の右上コーナー位置に置き,ラベル内の座標を変化させる:
Table[PathGraph[Range[3], VertexSize -> 0.5, 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}}}]Placedをラッパーで使って複数のラベルを置く:
PathGraph[{1, 2, 3, Labeled[4, Placed[{"lbl1", "lbl2"}, {Above, Below}]]}, {12, 23, 34}]PathGraph[{1, 2, 3, Labeled[4, Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]]}, {12, 23, 34}]VertexLabelsを使って複数のラベルを置く:
PathGraph[{12, 23, 34}, VertexLabels -> {4 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]Placedの引数を使ってTooltipを含むフォーマットを制御する:
PathGraph[Range[4], VertexLabels -> Placed["Name", Tooltip]]あるいはStatusAreaを含むフォーマットを制御する:
PathGraph[Range[4], VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]PathGraph[Range[4], VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 4}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]PathGraph[Range[4], VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 4}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]PathGraph[Range[4], VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 4}]]VertexShape (5)
Graphics,ImageあるいはGraphics3Dを頂点の形に使う:
Table[PathGraph[Range[4], VertexShape -> s, VertexSize -> Large], {s, {[image], [image], [image]}}]PathGraph[Range[4], VertexShape -> {2 -> [image]}, VertexSize -> Large]VertexShapeはVertexSizeと組み合せることができる:
Table[PathGraph[Range[4], VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]VertexShapeはVertexStyleの影響を受けない:
PathGraph[Range[4], VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunctionはVertexShapeより優先順位が高い:
PathGraph[Range[4], VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
組込みのVertexShapeFunctionコレクションのリストを得る:
ResourceData["VertexShapeFunction"]"Basic"コレクション中のVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Basic"]Table[PathGraph[{12, 23, 34}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[PathGraph[{12, 23, 34}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]"Rounded"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Rounded"]Table[PathGraph[{12, 23, 34}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]"Concave"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Concave"]Table[PathGraph[{12, 23, 34}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]PathGraph[{12, 23, 34}, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]PathGraph[{12, 23, 34}, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]PathGraph[Range[4], 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}}]
];PathGraph[Range[4], VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]PathGraph[Range[4], 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}]}PathGraph[Range[4], VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunctionはVertexSizeと組み合せることができる:
PathGraph[Range[4], VertexShapeFunction -> "Star", VertexSize -> {2 -> 0.3, 0.2}]VertexShapeFunctionはVertexShapeより優先順位が高い:
PathGraph[Range[4], VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
PathGraph[Range[4], VertexSize -> Automatic]Table[PathGraph[Range[4], VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[PathGraph[Range[4], VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[PathGraph[Range[4], VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[PathGraph[Range[4], VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]PathGraph[Range[4], VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSizeはVertexShapeFunctionと組み合せることができる:
Table[PathGraph[Range[4], VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSizeはVertexShapeと組み合せることができる:
Table[PathGraph[Range[4], VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VertexStyle (5)
Table[PathGraph[Range[5], VertexStyle -> style, VertexSize -> 0.4, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]PathGraph[Range[5], 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}]PathGraph[Range[5], 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}]}PathGraph[Range[5], VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyleはBaseStyleと組み合せることができる:
PathGraph[Range[5], VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.4]VertexStyleはBaseStyleより優先順位が高い:
PathGraph[Range[5], VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.4]VertexShapeはVertexStyleの影響を受けない:
PathGraph[Range[5], VertexSize -> 0.4, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (2)
アプリケーション (6)
経路グラフのGraphCenter:
Table[HighlightGraph[#, GraphCenter[#]]&[PathGraph[Range[i], VertexSize -> 0.2]], {i, 3, 6}]Table[HighlightGraph[#, GraphPeriphery[#]]&[PathGraph[Range[i], VertexSize -> 0.2]], {i, 3, 6}]VertexEccentricity[PathGraph[Range[20]], #]& /@ Range[4]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 = PathGraph[Range[20], VertexSize -> Medium], FindVertexEccentricityPath[g, u]], {u, Range[4]}]Table[GraphRadius[PathGraph[Range[i]]], {i, 3, 6}]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[#]]&[PathGraph[Range[i], VertexSize -> Medium]], {i, 3, 6}]Table[GraphDiameter[PathGraph[Range[i]]], {i, 3, 6}]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[#]]&[PathGraph[Range[i], VertexSize -> Medium]], {i, 3, 6}]PathGraphの異なる中心性を可視化する:
HighlightCentrality[g_, cc_] := HighlightGraph[g, Table[Style[VertexList[g][[i]], ColorData["TemperatureMap"][cc[[i]] / Max[cc]]], {i, VertexCount[g]}]];g = PathGraph[Range[25], VertexSize -> Large];HighlightCentrality[g, DegreeCentrality[g]]HighlightCentrality[g, ClosenessCentrality[g]]HighlightCentrality[g, EigenvectorCentrality[g]]特性と関係 (10)
VertexCountとEdgeCountを使って頂点と辺の数を数える:
g = PathGraph[Range[20]]{VertexCount[g], EdgeCount[g]}VertexListとEdgeListを使って頂点と辺を標準的な順序で列挙する:
g = PathGraph[{12, 23, 34}];{VertexList[g], EdgeList[g]}g1 = PathGraph[{23, 12, 34}];{VertexList[g1], EdgeList[g1]}g2 = PathGraph[{34, 23, 12}];{VertexList[g2], EdgeList[g2]}隣接行列の行と列はVertexListで与えられる順に従う:
g = PathGraph[{ab, bc, c -> d}];VertexList[g]TableForm[Normal@AdjacencyMatrix[g], TableHeadings -> {s = Style[#, Blue]& /@ %, s}]グラフからIncidenceMatrixを計算する:
g = PathGraph[{ab, bc, c -> d}];m = IncidenceMatrix[g];行順はVertexList,列順はEdgeListで与えられる:
{VertexList[g], EdgeList[g]}TableForm[Normal@m, TableHeadings -> {Style[#, Blue]& /@ VertexList[g], Style[#, Blue]& /@ EdgeList[g]}]Graph[{12, 23, 22}]PathGraphQ[%]CycleGraph[5]PathGraphQ[%]g = CycleGraph[5]{ConnectedGraphQ[g], PathGraphQ[g]}VertexDegree[g]TreeGraphQ[PathGraph[{12, 23, 34}]]PathGraph[{12, 23, 34}]AcyclicGraphQ[%]PathGraph[Range[21]]{LineGraph[%], PathGraph[Range[20]]}IsomorphicGraphQ@@%テキスト
Wolfram Research (2010), PathGraph, Wolfram言語関数, https://reference.wolfram.com/language/ref/PathGraph.html (2015年に更新).
CMS
Wolfram Language. 2010. "PathGraph." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/PathGraph.html.
APA
Wolfram Language. (2010). PathGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PathGraph.html
BibTeX
@misc{reference.wolfram_2026_pathgraph, author="Wolfram Research", title="{PathGraph}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/PathGraph.html}", note=[Accessed: 13-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_pathgraph, organization={Wolfram Research}, title={PathGraph}, year={2015}, url={https://reference.wolfram.com/language/ref/PathGraph.html}, note=[Accessed: 13-November-2026]}