({{, (RefLink[PathGraph, paclet:ref/PathGraph])[{(Subscript[v, 1]),(Subscript[v, 2]),…}] 
yields a path with vertices (Subscript[v, i]) and edges between (Subscript[v, i]) and (Subscript[v, i+ 1 ]).}, {, (RefLink[PathGraph, paclet:ref/PathGraph])[{(Subscript[e, 1]),(Subscript[e, 2]),…}]
yields a path with edges (Subscript[e, j]).}, {, (RefLink[PathGraph, paclet:ref/PathGraph])[{(Subscript[v, 1]),(Subscript[v, 2]),…},{(Subscript[e, 1]),(Subscript[e, 2]),…}]
yields a path with vertices (Subscript[v, i]) and edges (Subscript[e, j]).}, {, (RefLink[PathGraph, paclet:ref/PathGraph])[{…,(Subscript[w, i])[(Subscript[v, i]),…],…},{…,(Subscript[w, j])[(Subscript[e, j]),…],…}]
yields a path with vertex and edge properties defined by the symbolic wrappers (Subscript[w, k]).}, {, (RefLink[PathGraph, paclet:ref/PathGraph])[{(Subscript[v, i])->(Subscript[v, j]),…}]
uses rules (Subscript[v, i])->(Subscript[v, j]) to specify a path.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[PathGraph, paclet:ref/PathGraph]) generates a (RefLink[Graph, paclet:ref/Graph]) object.

(RefLink[PathGraph, paclet:ref/PathGraph]) supports the same vertices, edges, wrappers, and options as (RefLink[Graph, paclet:ref/Graph]).

An undirected path graph is a connected graph where each vertex has at most degree two.

A directed path graph is a connected graph where each vertex has at most in-degree one and at most out-degree one.

(RefLink[PathGraph, paclet:ref/PathGraph]) can only represent self-avoiding paths, except for cycles.

OpenersPrimaryExamplesSection(Spacer1)Examples  (106)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

A path constructed from a list of vertices:

PathGraph[{a,b,c}]

PathGraph[Range[25]]

A list of edges:

PathGraph[Table[i\[UndirectedEdge]i+1,{i,20}]]

OpenersExampleSection1(Spacer1)Scope  (6)

OpenersExampleSubsection0(Spacer1)Connectivity  (6)

Create an undirected graph using <-> characters, entering the character as (Key0[esc]) ue (Key0[esc]):

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]

Create a directed graph using -> characters, entering the character as (Key0[esc]) de (Key0[esc]):

PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeStyle->Arrowheads[Medium]]

Create a directed graph from a list of rules:

PathGraph[{1->2,2->3,3->4},EdgeStyle->Arrowheads[Medium]]

Create an undirected graph from a list of rules:

PathGraph[{1->2,2->3,3->4},DirectedEdges->False]

Use (RefLink[VertexList, paclet:ref/VertexList]) and (RefLink[EdgeList, paclet:ref/EdgeList]) to get vertices and edges:

{g1,g2}={PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}],PathGraph[{2\[UndirectedEdge]3,1\[UndirectedEdge]2,3\[UndirectedEdge]4}]}

The ordering for edges is the order in which they were entered:

EdgeList/@{g1,g2}

The ordering for vertices is the order in which they entered in the edges:

VertexList/@{g1,g2}

Use an explicit vertex list to control the ordering used by (RefLink[VertexList, paclet:ref/VertexList]):

{g1,g2}={PathGraph[{1,2,3,4},{2\[UndirectedEdge]3,1\[UndirectedEdge]2,3\[UndirectedEdge]4}],PathGraph[{3,2,1,4},{2\[UndirectedEdge]3,1\[UndirectedEdge]2,3\[UndirectedEdge]4}]}

The input vertex list controls the resulting vertex order:

VertexList/@{g1,g2}

Any expression can be used as vertices:

{PathGraph[{a\[UndirectedEdge]b,b\[UndirectedEdge]c}],PathGraph[{"foo"\[UndirectedEdge]"bar","bar"\[UndirectedEdge]"gnu"}],
PathGraph[{\[UndirectedEdge],\[UndirectedEdge]}]}

VertexList/@%

OpenersExampleSection2(Spacer1)Options  (82)

OpenersExampleSubsection1(Spacer1)DirectedEdges  (2)

By default, a directed path is generated when giving a list of rules:

PathGraph[{1->2,2->3,3->4},EdgeStyle->Arrowheads[Medium]]

Use (RefLink[DirectedEdges, paclet:ref/DirectedEdges])->(RefLink[False, paclet:ref/False]) to interpret rules as undirected edges:

PathGraph[{1->2,2->3,3->4},DirectedEdges->False]

Use (RefLink[DirectedEdge, paclet:ref/DirectedEdge]) or (RefLink[UndirectedEdge, paclet:ref/UndirectedEdge]) to directly specify whether a graph is directed or not:

{PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeStyle->Arrowheads[Medium]],PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]}

OpenersExampleSubsection2(Spacer1)EdgeLabels  (7)

Label the edge 1<->2:

PathGraph[Range[4],EdgeLabels->{1\[UndirectedEdge]2->"Hello"}]

Label all edges individually:

el={1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4};

PathGraph[el,EdgeLabels->Table[el[[i]]->(Subscript["e", i]),{i,Length[el]}]]

Use any expression as a label:

PathGraph[Range[4],EdgeLabels->{1\[UndirectedEdge]2->,2\[UndirectedEdge]3->,3\[UndirectedEdge]4-> }]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement along an edge:

Table[PathGraph[Range[4],EdgeLabels->{2\[UndirectedEdge]3->Placed["■■■",p]},PlotLabel->p],{p,{"Start","Middle","End"}}]

Use explicit coordinates to place labels:

Table[PathGraph[Range[4],EdgeLabels->{2\[UndirectedEdge]3->Placed["■■■",p]},PlotLabel->p,BaselinePosition->Bottom],{p,{0,1/2,1}}]

Vary positions within the label:

Table[PathGraph[Range[4],EdgeLabels->{2\[UndirectedEdge]3->Placed["■■■",{1/2,p}]},PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels using (RefLink[Placed, paclet:ref/Placed]) in a wrapper:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Labeled[3\[UndirectedEdge]4,Placed[{"lbl1","lbl2"},{"Start","End"}]]}]

Any number of labels can be used:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Labeled[3\[UndirectedEdge]4,Placed[{"lbl1","lbl2","lbl3"},{"Start","Middle","End"}]]}]

Place multiple labels using (RefLink[EdgeLabels, paclet:ref/EdgeLabels]):

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},EdgeLabels->{3\[UndirectedEdge]4->Placed[{"lbl1","lbl2"},{"Start","End"}]}]

Use automatic labeling by values through (RefLink[Tooltip, paclet:ref/Tooltip]) and (RefLink[StatusArea, paclet:ref/StatusArea]):

PathGraph[Range[4],EdgeLabels->Placed["Name",Tooltip]]

PathGraph[Range[4],EdgeLabels->Placed["Name",StatusArea]]

OpenersExampleSubsection3(Spacer1)EdgeShapeFunction  (6)

Get a list of built-in settings for (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]):

GraphElementData["Edge"]

Undirected edges including the basic line:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},EdgeShapeFunction->"Line"]

Lines with different glyphs on the edges:

Table[PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,{"BoxLine","DiamondLine","DotLine"}}]

Directed edges including solid arrows:

Table[PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","FilledArrow"]}]

Line arrows:

Table[PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","UnfilledArrow"]}]

Open arrows:

Table[PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","CarvedArrow"]}]

Specify an edge function for an individual edge:

PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArrow"}]

Combine with a different default edge function:

PathGraph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]4},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArcArrow","CarvedArrow"}]

Draw edges by running a program:

ef[pts_List,e_]:=
Block[{s=0.015,g=},{Arrowheads[{{s,0.33,g},{s,0.67,g}}],Arrow[pts]}]

PathGraph[Range[4],EdgeShapeFunction->ef]

(RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]) can be combined with (RefLink[EdgeStyle, paclet:ref/EdgeStyle]):

PathGraph[Range[4],EdgeStyle->Blue,EdgeShapeFunction->(Line[#1]&)]

(RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]) has higher priority than (RefLink[EdgeStyle, paclet:ref/EdgeStyle]):

PathGraph[Range[4],EdgeStyle->Blue,EdgeShapeFunction->({Red,Line[#1]}&)]

OpenersExampleSubsection4(Spacer1)EdgeStyle  (2)

Style all edges:

Table[PathGraph[Range[10],EdgeStyle->style,PlotLabel->style],{style,{Gray,Dashed,Thick}}]

Style individual edges:

PathGraph[Range[5],EdgeStyle->{1\[UndirectedEdge]2->Blue,2\[UndirectedEdge]3->Dashed}]

OpenersExampleSubsection5(Spacer1)EdgeWeight  (2)

Specify a weight for all edges:

PathGraph[Range[4],EdgeWeight->RandomInteger[5,3]]

WeightedAdjacencyMatrix[%]//MatrixForm

Use any numeric expression as a weight:

PathGraph[Range[4],EdgeWeight->{a,b,c}]

WeightedAdjacencyMatrix[%]//MatrixForm

OpenersExampleSubsection6(Spacer1)GraphHighlight  (3)

Highlight the vertex 1:

PathGraph[Range[5],VertexSize->Medium,GraphHighlight->{1}]

Highlight the edge 2<->3:

PathGraph[Range[5],VertexSize->Tiny,GraphHighlight->{2\[UndirectedEdge]3}]

Highlight vertices and edges:

PathGraph[Range[5],VertexSize->Tiny,GraphHighlight->{1,2,1\[UndirectedEdge]2,3\[UndirectedEdge]4}]

OpenersExampleSubsection7(Spacer1)GraphHighlightStyle  (2)

Get a list of built-in settings for (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]):

GraphElementData["GraphHighlightStyle"]

Use built-in settings for (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]):

PathGraph[Range[20],GraphHighlight->{1,2\[UndirectedEdge]3},VertexSize->Small,GraphHighlightStyle->#,PlotLabel->#]&/@Select[GraphElementData["GraphHighlightStyle"],#=!=Automatic&]

OpenersExampleSubsection8(Spacer1)GraphLayout  (5)

By default, the layout is chosen automatically:

PathGraph[Range[10],GraphLayout->Automatic]

Specify layouts on special curves:

Table[PathGraph[Range[20],GraphLayout->l,PlotLabel->l],{l,{"CircularEmbedding","SpiralEmbedding"}}]

Specify layouts that satisfy optimality criteria:

Table[PathGraph[Range[20],GraphLayout->l,PlotLabel->l],{l,{"SpringEmbedding","SpringElectricalEmbedding","HighDimensionalEmbedding"}}]

(RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) overrides (RefLink[GraphLayout, paclet:ref/GraphLayout]) coordinates:

{PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},GraphLayout->"SpringElectricalEmbedding"],
PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},GraphLayout->"SpringElectricalEmbedding",VertexCoordinates->Table[{i,i},{i,0,3}]]}

Use (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions]) to extract (RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) computed using a layout algorithm:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]

AbsoluteOptions[%,VertexCoordinates]

OpenersExampleSubsection9(Spacer1)PlotTheme  (4)

OpenersExampleSubsubsection0(Spacer1)Base Themes  (2)

Use a common base theme:

PathGraph[Range[20],PlotTheme->"Business"]

Use a monochrome theme:

PathGraph[Range[20],PlotTheme->"Monochrome"]

OpenersExampleSubsubsection1(Spacer1)Feature Themes  (2)

Use a large graph theme:

PathGraph[Range[20],PlotTheme->"LargeGraph"]

Use a classic diagram theme:

PathGraph[Range[20],PlotTheme->"ClassicDiagram"]

OpenersExampleSubsection10(Spacer1)Properties  (3)

Specify a property for vertices:

PathGraph[Range[5],Properties->{4->{VertexLabels-> "hello"}}]

Edges:

PathGraph[Range[5],Properties->{1\[UndirectedEdge]2->{EdgeLabels-> "hello"}}]

Graph itself:

PathGraph[Range[5],Properties->{"GraphProperties"->{"Message"-> "hello"}}]

PropertyValue[%,"Message"]

OpenersExampleSubsection11(Spacer1)VertexCoordinates  (3)

By default, any vertex coordinates are computed automatically:

PathGraph[Range[4]]

Extract the resulting vertex coordinates using (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions]):

AbsoluteOptions[%,VertexCoordinates]

Specify a layout function along an ellipse:

ellipseLayout[n_,{a_,b_}]:=Table[{a Cos[2Pi/n u],b Sin[2Pi/n u]},{u,1,n}]

Graphics[Point[ellipseLayout[20,{2,1}]]]

Use it to generate vertex coordinates for a graph:

PathGraph[Range[20],VertexCoordinates->ellipseLayout[20,{2,1}]]

(RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) has higher priority than (RefLink[GraphLayout, paclet:ref/GraphLayout]):

PathGraph[Range[4],VertexCoordinates->Table[{i,i},{i,4}],GraphLayout->"CircularEmbedding"]

OpenersExampleSubsection12(Spacer1)VertexLabels  (13)

Use vertex names as labels:

PathGraph[Range[4],VertexLabels->"Name"]

Label individual vertices:

PathGraph[Range[4],VertexLabels->{2->"one"}]

Label all vertices:

PathGraph[Range[4],VertexLabels->Table[i->(Subscript[v, i]),{i,4}]]

Use any expression as a label:

PathGraph[Range[4],VertexLabels->{1->,2->,3->},ImagePadding->20]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement, including outside positions:

Table[PathGraph[Range[4],VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,4}],PlotLabel->p],{p,{Before,After,Below,Above}}]

Symbolic outside corner positions:

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}]

Symbolic inside positions:

Table[PathGraph[Range[3],VertexSize->0.5,VertexLabels->Table[i->Placed["■■■",p],{i,3}],VertexShapeFunction->"Square",PlotLabel->p],{p,{Left,Top,Right,Bottom}}]

Symbolic inside corner positions:

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}]

Use explicit coordinates to place the center of labels:

Table[PathGraph[Range[3],VertexSize->0.5,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,p],{i,3}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place all labels at the upper-right corner of the vertex and vary the coordinates within the label:

Table[PathGraph[Range[3],VertexSize->0.5,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,{{1,1},p}],{i,3}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels using (RefLink[Placed, paclet:ref/Placed]) in a wrapper:

PathGraph[{1,2,3,Labeled[4,Placed[{"lbl1","lbl2"},{Above,Below}]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]

Any number of labels can be used:

PathGraph[{1,2,3,Labeled[4,Placed[{"lbl1","lbl2","lbl3","lbl4"},{Above,After,Below,Before}]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]

Place multiple labels using (RefLink[VertexLabels, paclet:ref/VertexLabels]):

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexLabels->{4->Placed[{"lbl1","lbl2"},{Above,Below}]}]

Use the argument to (RefLink[Placed, paclet:ref/Placed]) to control formatting including (RefLink[Tooltip, paclet:ref/Tooltip]):

PathGraph[Range[4],VertexLabels->Placed["Name",Tooltip]]

Or (RefLink[StatusArea, paclet:ref/StatusArea]):

PathGraph[Range[4],VertexLabels->Placed["Name",StatusArea]]

Use more elaborate formatting functions:

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}]]

OpenersExampleSubsection13(Spacer1)VertexShape  (5)

Use any (RefLink[Graphics, paclet:ref/Graphics]), (RefLink[Image, paclet:ref/Image]), or (RefLink[Graphics3D, paclet:ref/Graphics3D]) as a vertex shape:

Table[PathGraph[Range[4],VertexShape->s,VertexSize->Large],{s,{,,}}]

Specify vertex shapes for individual vertices:

PathGraph[Range[4],VertexShape->{2->},VertexSize->Large]

(RefLink[VertexShape, paclet:ref/VertexShape]) can be combined with (RefLink[VertexSize, paclet:ref/VertexSize]):

Table[PathGraph[Range[4],VertexSize->s,VertexShape->,PlotLabel->s],{s,{Small,Large}}]

(RefLink[VertexShape, paclet:ref/VertexShape]) is not affected by (RefLink[VertexStyle, paclet:ref/VertexStyle]):

PathGraph[Range[4],VertexSize->0.2,VertexShape->,VertexStyle->Blue]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

PathGraph[Range[4],VertexSize->0.1,VertexShapeFunction->"Square",VertexShape->]

OpenersExampleSubsection14(Spacer1)VertexShapeFunction  (10)

Get a list of built-in collections for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

GraphElementData["Vertex"]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Basic" collection:

GraphElementData["Vertex","Basic"]

Simple basic shapes:

Table[PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"Triangle","Square","Rectangle","Pentagon","Hexagon","Octagon"}}]

Common basic shapes:

Table[PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"DownTrapezoid","UpTrapezoid","Parallelogram","FiveDown","Circle","Diamond","Star","Capsule"}}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Rounded" collection:

GraphElementData["Vertex","Rounded"]

Table[PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Rounded"]}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Concave" collection:

GraphElementData["Vertex","Concave"]

Table[PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Concave"]}]

Draw individual vertices:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexShapeFunction->{ 1->"Square"},VertexSize->0.2]

Combine with a default vertex function:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},VertexShapeFunction->{ 1->"Square","Triangle"},VertexSize->0.2]

Draw vertices using a predefined graphic:

PathGraph[Range[4],VertexShapeFunction->(Inset[,#]&)]

Draw vertices by running a program:

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]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/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]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/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]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexSize, paclet:ref/VertexSize]):

PathGraph[Range[4],VertexShapeFunction->"Star",VertexSize->{2->0.3,0.2}]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

PathGraph[Range[4],VertexSize->0.3,VertexShapeFunction->"Star",VertexShape->]

OpenersExampleSubsection15(Spacer1)VertexSize  (8)

By default, the size of vertices is computed automatically:

PathGraph[Range[4],VertexSize->Automatic]

Specify the size of all vertices using symbolic vertex size:

Table[PathGraph[Range[4],VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Use a fraction of the minimum distance between vertex coordinates:

Table[PathGraph[Range[4],VertexSize->s,PlotLabel->s],{s,0.1,1,0.3}]

Use a fraction of the overall diagonal for all vertex coordinates:

Table[PathGraph[Range[4],VertexSize->{"Scaled", s},PlotLabel->{"Scaled", s}],{s,0.1,1,0.3}]

Specify size in both the x and y directions:

Table[PathGraph[Range[4],VertexSize->s,PlotLabel->s],{s,{{0.1,0.2},{0.2,0.1}}}]

Specify a size for individual vertices:

PathGraph[Range[4],VertexSize->{1->0.2,2->0.3}]

(RefLink[VertexSize, paclet:ref/VertexSize]) can be combined with (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

Table[PathGraph[Range[4],VertexSize->s,VertexShapeFunction->"Square",PlotLabel->s],{s,{0.05,0.1,0.2}}]

(RefLink[VertexSize, paclet:ref/VertexSize]) can be combined with (RefLink[VertexShape, paclet:ref/VertexShape]):

Table[PathGraph[Range[4],VertexSize->s,VertexShape->,PlotLabel->s],{s,{0.1,0.2,0.4}}]

OpenersExampleSubsection16(Spacer1)VertexStyle  (5)

Style all vertices:

Table[PathGraph[Range[5],VertexStyle->style,VertexSize->0.4,PlotLabel->style],{style,{Yellow,EdgeForm[Dashed]}}]

Style individual vertices:

PathGraph[Range[5],VertexStyle->{1->Blue,2->Red},VertexSize->0.2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/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]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/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]

(RefLink[VertexStyle, paclet:ref/VertexStyle]) can be combined with (RefLink[BaseStyle, paclet:ref/BaseStyle]):

PathGraph[Range[5],VertexStyle->LightBlue,BaseStyle->EdgeForm[Dotted],VertexSize->0.4]

(RefLink[VertexStyle, paclet:ref/VertexStyle]) has higher priority than (RefLink[BaseStyle, paclet:ref/BaseStyle]):

PathGraph[Range[5],VertexStyle->LightBlue,BaseStyle->Gray,VertexSize->0.4]

(RefLink[VertexShape, paclet:ref/VertexShape]) is not affected by (RefLink[VertexStyle, paclet:ref/VertexStyle]):

PathGraph[Range[5],VertexSize->0.4,VertexShape->,VertexStyle->Blue]

OpenersExampleSubsection17(Spacer1)VertexWeight  (2)

Set the weight for all vertices:

PathGraph[Range[4],VertexWeight->{2,3,4,5}]

PropertyValue[{%,1},VertexWeight]

Use any numeric expression as a weight:

PathGraph[Range[4],VertexWeight->{a,b,c,d}]

PropertyValue[{%,1},VertexWeight]

OpenersExampleSection3(Spacer1)Applications  (6)

The (RefLink[GraphCenter, paclet:ref/GraphCenter]) of path graphs:

Table[HighlightGraph[#,GraphCenter[#]]&[PathGraph[Range[i],VertexSize->0.2]],{i,3,6}]

The (RefLink[GraphPeriphery, paclet:ref/GraphPeriphery]):

Table[HighlightGraph[#,GraphPeriphery[#]]&[PathGraph[Range[i],VertexSize->0.2]],{i,3,6}]

The (RefLink[VertexEccentricity, paclet:ref/VertexEccentricity]):

VertexEccentricity[PathGraph[Range[20]],#]&/@Range[4]

Highlight the vertex eccentricity path:

FindVertexEccentricityPath[g_?UndirectedGraphQ,u_]/;MemberQ[VertexList[g],u]:=Module[{d=GraphDistanceMatrix[g],v,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]}]

The (RefLink[GraphRadius, paclet:ref/GraphRadius]):

Table[GraphRadius[PathGraph[Range[i]]],{i,3,6}]

Highlight the radius path:

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}]

The (RefLink[GraphDiameter, paclet:ref/GraphDiameter]):

Table[GraphDiameter[PathGraph[Range[i]]],{i,3,6}]

Highlight the diameter path:

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}]

Visualize different centralities for (RefLink[PathGraph, paclet:ref/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]]

Highlight the closeness centrality:

HighlightCentrality[g,ClosenessCentrality[g]]

Highlight the eigenvector centrality:

HighlightCentrality[g,EigenvectorCentrality[g]]

OpenersExampleSection4(Spacer1)Properties & Relations  (10)

Use (RefLink[VertexCount, paclet:ref/VertexCount]) and (RefLink[EdgeCount, paclet:ref/EdgeCount]) to count vertices and edges:

g=PathGraph[Range[20]]

{VertexCount[g],EdgeCount[g]}

Use (RefLink[VertexList, paclet:ref/VertexList]) and (RefLink[EdgeList, paclet:ref/EdgeList]) to enumerate vertices and edges in standard order:

g=PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}];

{VertexList[g],EdgeList[g]}

Edges and vertices are given in the order they are input:

g1=PathGraph[{2\[UndirectedEdge]3,1\[UndirectedEdge]2,3\[UndirectedEdge]4}];

{VertexList[g1],EdgeList[g1]}

g2=PathGraph[{3\[UndirectedEdge]4,2\[UndirectedEdge]3,1\[UndirectedEdge]2}];

{VertexList[g2],EdgeList[g2]}

Rows and columns of the adjacency matrix follow the order given by (RefLink[VertexList, paclet:ref/VertexList]):

g=PathGraph[{a\[DirectedEdge]b,b\[DirectedEdge]c,c->d}];

VertexList[g]

TableForm[Normal@AdjacencyMatrix[g],TableHeadings->{s=Style[#,Blue]&/@%,s}]

Compute the (RefLink[IncidenceMatrix, paclet:ref/IncidenceMatrix]) from a graph:

g=PathGraph[{a\[DirectedEdge]b,b\[DirectedEdge]c,c->d}];

m=IncidenceMatrix[g];

The row ordering is given by (RefLink[VertexList, paclet:ref/VertexList]) and column ordering is given by (RefLink[EdgeList, paclet:ref/EdgeList]):

{VertexList[g],EdgeList[g]}

TableForm[Normal@m,TableHeadings->{Style[#,Blue]&/@VertexList[g],Style[#,Blue]&/@EdgeList[g]}]

A path graph is a loop-free graph:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,2\[UndirectedEdge]2}]

PathGraphQ[%]

A path graph that starts and ends in the same vertex is a cycle graph:

CycleGraph[5]

PathGraphQ[%]

A path graph is connected and each vertex has at most degree 2:

g=CycleGraph[5]

{ConnectedGraphQ[g],PathGraphQ[g]}

VertexDegree[g]

A path graph with no repeated vertices is a tree:

TreeGraphQ[PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]]

A path graph with no repeated vertices is acyclic:

PathGraph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4}]

AcyclicGraphQ[%]

The line graph of a path (Subscript[P, n]) is isomorphic to (Subscript[P, n-1]):

PathGraph[Range[21]]

{LineGraph[%],PathGraph[Range[20]]}

IsomorphicGraphQ@@%

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Graph, paclet:ref/Graph])  ▪  (RefLink[UndirectedEdge, paclet:ref/UndirectedEdge])  ▪  (RefLink[DirectedEdge, paclet:ref/DirectedEdge])  ▪  (RefLink[PathGraphQ, paclet:ref/PathGraphQ])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}})}})