({{, (RefLink[Graph, paclet:ref/Graph])[{(Subscript[e, 1]),(Subscript[e, 2]),…}]
yields a graph with edges (Subscript[e, j]).}, {, (RefLink[Graph, paclet:ref/Graph])[{(Subscript[v, 1]),(Subscript[v, 2]),…},{(Subscript[e, 1]),(Subscript[e, 2]),…}]
yields the graph with vertices (Subscript[v, i]) and edges (Subscript[e, j]). }, {, (RefLink[Graph, paclet:ref/Graph])[{…,(Subscript[w, i])[(Subscript[v, i]),…],…},{…,(Subscript[w, j])[(Subscript[e, j]),…],…}]
yields a graph with vertex and edge properties defined by the symbolic wrappers (Subscript[w, k]).}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[Graph, paclet:ref/Graph])[…] displays in a notebook as a plot of a graph.

(RefLink[Graph, paclet:ref/Graph])[…] is always converted to an optimized standard form with structure (RefLink[Graph, paclet:ref/Graph])[vertices,edges,…].

(RefLink[Graph, paclet:ref/Graph]) is treated as a raw object by functions like (RefLink[AtomQ, paclet:ref/AtomQ]), and for purposes of pattern matching.

An undirected edge between u and v can be given as u<->v, u<->v, (RefLink[UndirectedEdge, paclet:ref/UndirectedEdge])[u,v] or (RefLink[TwoWayRule, paclet:ref/TwoWayRule])[u,v]. The character <-> can be entered as (Key0[esc]) ue (Key0[esc]).

A directed edge from u to v can be given as u->v, u->v, (RefLink[DirectedEdge, paclet:ref/DirectedEdge])[u,v], or (RefLink[Rule, paclet:ref/Rule])[u,v]. The character -> can be entered as (Key0[esc]) de (Key0[esc]).

An undirected graph is specified using a collection of undirected edges.

A directed graph is specified using a collection of directed edges.

The following special wrappers can be used for vertices and edges:

The possible label placements are given in (RefLink[VertexLabels, paclet:ref/VertexLabels]) and (RefLink[EdgeLabels, paclet:ref/EdgeLabels]), respectively.

(RefLink[Property, paclet:ref/Property]) can be used to associate properties with vertices and edges:

The following standard properties are supported for vertices:

The following standard properties are supported for edges:

(RefLink[Graph, paclet:ref/Graph]) has the same options as (RefLink[Graphics, paclet:ref/Graphics]), with the following additions and changes:

Possible settings for (RefLink[PlotTheme, paclet:ref/PlotTheme]) include common base themes, color feature themes, font features themes, and size features themes.

Graph feature themes affect the plots of vertices and edges. Feature themes include:

(RefLink[Properties, paclet:ref/Properties])->{a->{(Subscript[name, 1])->(Subscript[val, 1]),…},…} associates the property (Subscript[name, 1])->(Subscript[val, 1]) etc. with a that can be a vertex, edge, or the graph itself. The following strings for a have special meanings:

With the setting (RefLink[VertexCoordinates, paclet:ref/VertexCoordinates])->(RefLink[Automatic, paclet:ref/Automatic]), the placement of vertices and routing of edges is computed automatically, based on the setting for (RefLink[GraphLayout, paclet:ref/GraphLayout]).

Style and other specifications for edges are effectively applied in the order (RefLink[PlotTheme, paclet:ref/PlotTheme]), (RefLink[EdgeStyle, paclet:ref/EdgeStyle]), (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]), (RefLink[Style, paclet:ref/Style]) and other wrappers, and (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]), with later specifications overriding earlier ones.

Style and other specifications for vertices are effectively applied in the order (RefLink[PlotTheme, paclet:ref/PlotTheme]), (RefLink[VertexStyle, paclet:ref/VertexStyle]), (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]), (RefLink[Style, paclet:ref/Style]) and other wrappers, and (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]), with later specifications overriding earlier ones.

Label style and other specifications for edge labels are effectively applied in the order (RefLink[PlotTheme, paclet:ref/PlotTheme]), (RefLink[EdgeLabelStyle, paclet:ref/EdgeLabelStyle]), (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]), (RefLink[Labeled, paclet:ref/Labeled]), and (RefLink[EdgeLabels, paclet:ref/EdgeLabels]), with later specifications overriding earlier ones.

Label style and other specifications for vertex labels are effectively applied in the order (RefLink[PlotTheme, paclet:ref/PlotTheme]), (RefLink[VertexLabelStyle, paclet:ref/VertexLabelStyle]), (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]), (RefLink[Labeled, paclet:ref/Labeled]), and (RefLink[VertexLabels, paclet:ref/VertexLabels]), with later specifications overriding earlier ones.

OpenersPrimaryExamplesSection(Spacer1)Examples  (124)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

An undirected graph:

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

A directed graph:

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

Style vertices and edges:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->Orange,EdgeStyle->Green]

Use wrappers to input directly:

Graph[{1,2,Style[3,Red]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Style[3\[UndirectedEdge]1,Blue]}]

Label vertices and edges:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Labeled[3\[UndirectedEdge]1,"hello"]},VertexLabels->"Name"]

Use different vertices and edges:

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},VertexShapeFunction->"Diamond",VertexSize->Medium]

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->"CarvedArcArrow"]

OpenersExampleSection1(Spacer1)Scope  (27)

OpenersExampleSubsection0(Spacer1)Connectivity  (8)

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

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

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

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

Create a directed graph from a list of rules:

Graph[{1->2,2->3,3->1}]

Create an undirected graph from a list of rules:

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

Specify a graph with isolated vertices by giving an explicit list of vertices:

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

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

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

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 were 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}={Graph[{1,2,3},{2\[UndirectedEdge]3,1\[UndirectedEdge]2,3\[UndirectedEdge]1}],Graph[{3,2,1},{2\[UndirectedEdge]3,1\[UndirectedEdge]2,3\[UndirectedEdge]1}]}

The input vertex list controls the resulting vertex order:

VertexList/@{g1,g2}

Create undirected or directed graphs with self-loops:

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

Any expression can be used as vertices:

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

VertexList/@%

OpenersExampleSubsection1(Spacer1)Wrappers  (5)

Use wrappers on vertices or edges:

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

Wrappers can be nested:

{Graph[{1,2,Labeled[Style[3,Red],"hello"]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1}],Graph[{1,2,3},{Style[Labeled[1\[UndirectedEdge]2,"hello"],Red],2\[UndirectedEdge]3,3\[UndirectedEdge]1}]}

Add interactive behavior by wrappers such as (RefLink[Tooltip, paclet:ref/Tooltip]):

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Tooltip[Style[3\[UndirectedEdge]1,Red],"hello"]}]

Any object can be used in the tooltip:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Tooltip[Style[3\[UndirectedEdge]1,Red],Plot[Sin[x],{x,0,2Pi}]]}]

Use (RefLink[Button, paclet:ref/Button]) to trigger actions when clicking an edge or vertex:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Button[Style[3\[UndirectedEdge]1,Red],Speak["Edge from 3 to 1"]]}],Graph[{1,2,Button[Style[3,Red],Speak["Vertex 3"]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->Medium]}

Use (RefLink[PopupWindow, paclet:ref/PopupWindow]) to provide information drilldown:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,PopupWindow[Style[3\[UndirectedEdge]1,Red],DateListPlot[FinancialData["IBM","Jan. 1, 2004"]]]}]

OpenersExampleSubsection2(Spacer1)Styling  (8)

Set the style for all vertices or edges:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->Green],Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->Green]}

Style individual vertices or edges using options:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->{1->Green,Orange}],Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->{1\[UndirectedEdge]2->Green,Orange}]}

Use wrappers for individual styling:

{Graph[{Style[1,Green],2,3},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->Orange],Graph[{Style[1\[UndirectedEdge]2,Green],2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->Orange]}

Adjust the size of vertices using symbolic sizes:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Or use sizes in terms of the smallest distance between vertex centers:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,PlotLabel->s],{s,{0.1,0.2,0.5,1}}]

Use built-in collections for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

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

Rounded shapes:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->s,VertexSize->0.2,PlotLabel->Style[s,9]],{s,GraphElementData["VertexShapeFunction","Rounded"]}]

Concave shapes:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->s,VertexSize->0.2,PlotLabel->s],{s,GraphElementData["VertexShapeFunction","Concave"]}]

Draw individual vertices:

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

Combine with a default vertex function:

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

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

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShape->s,VertexSize->Medium],{s,{,,}}]

Use built-in collections for (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]):

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

Directed edges including solid arrows:

Table[Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->Style[ef,9]],{ef,GraphElementData["EdgeShapeFunction","FilledArrow"]}]

Line arrows:

Table[Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->Style[ef,9]],{ef,GraphElementData["EdgeShapeFunction","UnfilledArrow"]}]

Open arrows:

Table[Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->Style[ef,9]],{ef,GraphElementData["EdgeShapeFunction","CarvedArrow"]}]

Specify an edge function for an individual edge:

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

Combine with a different default edge function:

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArrow","CarvedArrow"}]

OpenersExampleSubsection3(Spacer1)Labeling  (6)

Label any edge or vertex:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Labeled[3\[UndirectedEdge]1,"hello"]}],Graph[{1,2,Labeled[3,"hello"]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1}]}

Use any expression as a label:

Table[Graph[{1,2,Labeled[3,l]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1}, ImagePadding->25],{l,{Sin[x],,}}]

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,Labeled[3\[UndirectedEdge]1,l]}],{l,{Sin[x],,}}]

Control the placement of vertex labels using (RefLink[Placed, paclet:ref/Placed]), including symbolic inside positions:

Table[Graph[{1,2,Labeled[3,Placed["■■",p]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotLabel->p,VertexSize->Large,VertexShapeFunction->"Square"],{p,{Left,Right,Bottom,Top}}]

Symbolic outside positions:

Table[Graph[{1,2,Labeled[3,Placed["■■",p]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotLabel->p,VertexShapeFunction->"Square",VertexSize->Small],{p,{Before,After,Below,Above}}]

Coordinate-based positions:

Table[Graph[{1,2,Labeled[3,Placed["■",p]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.25,VertexShapeFunction->"Square",PlotLabel->p,BaselinePosition->Axis],{p,{{0,0},{1/2,1/2},{1,1}}}]

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

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

Any number of labels can be used:

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

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

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

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

Table[Graph[{Labeled[1\[UndirectedEdge]2,Placed["■■",p]],2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotLabel->p,VertexSize->Small],{p,{"Start","Middle","End"}}]

Use explicit coordinates to place labels:

Table[Graph[{Labeled[1\[UndirectedEdge]2,Placed["■■",p]],2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotLabel->p,VertexSize->Small,BaselinePosition->Axis],{p,{0,1/4,1/3}}]

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

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

Any number of labels can be used:

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

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

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

OpenersExampleSection2(Spacer1)Options  (84)

OpenersExampleSubsection4(Spacer1)DirectedEdges  (2)

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

Graph[{1->2,2->3,3->1}]

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

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

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

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

OpenersExampleSubsection5(Spacer1)EdgeLabels  (7)

Label the edge 1<->2:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeLabels->{1\[UndirectedEdge]2->"Hello"}]

Label all edges individually:

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

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

Use any expression as a label:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeLabels->{1\[UndirectedEdge]2->,2\[UndirectedEdge]3->,3\[UndirectedEdge]1-> }]

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

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

Use explicit coordinates to place labels:

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

Vary positions within the label:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeLabels->{1\[UndirectedEdge]3->Placed["■■■",{1/2,p}]},PlotLabel->p,BaselinePosition->Axis],{p,{{0,0},{1/2,1/2},{1,1}}}]

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

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

Any number of labels can be used:

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

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

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

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeLabels->Placed["Name",Tooltip]]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeLabels->Placed["Name",StatusArea]]

OpenersExampleSubsection6(Spacer1)EdgeShapeFunction  (6)

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

GraphElementData["EdgeShapeFunction"]

Undirected edges including the basic line:

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

Lines with different glyphs on the edges:

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

Directed edges including solid arrows:

Table[Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->Style[ef,10]],{ef,GraphElementData["EdgeShapeFunction","FilledArrow"]}]

Line arrows:

Table[Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->Style[ef,9]],{ef,GraphElementData["EdgeShapeFunction","UnfilledArrow"]}]

Open arrows:

Table[Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->Style[ef,10]],{ef,GraphElementData["EdgeShapeFunction","CarvedArrow"]}]

Specify an edge function for an individual edge:

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

Combine with a different default edge function:

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArrow","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]}]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeShapeFunction->ef]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->Blue,EdgeShapeFunction->(Line[#1]&)]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->Blue,EdgeShapeFunction->({Red,Line[#1]}&)]

OpenersExampleSubsection7(Spacer1)EdgeStyle  (4)

Style all edges:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->style,PlotLabel->style],{style,{Gray,Dashed,Thick}}]

Style individual edges:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->{1\[UndirectedEdge]2->Blue,2\[UndirectedEdge]3->Dashed}]

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

ef1[el_,___]:=Arrow[el,0.1]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->Blue,EdgeShapeFunction->ef1]

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

ef2[el_,___]:={Red,Arrow[el,0.1]}

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeStyle->Blue,EdgeShapeFunction->ef2]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},BaseStyle->Red,EdgeStyle->Dashed]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},BaseStyle->Red,EdgeStyle->Blue]

OpenersExampleSubsection8(Spacer1)EdgeWeight  (2)

Specify a weight for all edges:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeWeight->RandomInteger[5,3]]

WeightedAdjacencyMatrix[%]//MatrixForm

Use any numeric expression as a weight:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},EdgeWeight->{a,b,c}]

WeightedAdjacencyMatrix[%]//MatrixForm

OpenersExampleSubsection9(Spacer1)GraphHighlight  (3)

Highlight the vertex 1:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->Tiny,GraphHighlight->{1}]

Highlight the edge 2<->3:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->Tiny,GraphHighlight->{2\[UndirectedEdge]3}]

Highlight vertices and edges:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->Tiny,GraphHighlight->{1,2,1\[UndirectedEdge]3,2\[UndirectedEdge]3}]

OpenersExampleSubsection10(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]):

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

OpenersExampleSubsection11(Spacer1)GraphLayout  (5)

By default, the layout is chosen automatically:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},GraphLayout->Automatic]

Specify layouts on special curves:

Table[Graph[Table[i\[UndirectedEdge]i+1,{i,20}],GraphLayout->l,PlotLabel->l],{l,{"CircularEmbedding","SpiralEmbedding"}}]

Specify layouts that satisfy optimality criteria:

el=EdgeList@GridGraph[{10,10}];

Table[
Graph[el,GraphLayout->l,PlotLabel->Style[l,10]],{l,{"SpringEmbedding","SpringElectricalEmbedding","HighDimensionalEmbedding"}}]

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

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

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

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

AbsoluteOptions[%,VertexCoordinates]

OpenersExampleSubsection12(Spacer1)PlotTheme  (4)

OpenersExampleSubsubsection0(Spacer1)Base Themes  (2)

Use a common base theme:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotTheme->"Business"]

Use a monochrome theme:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotTheme->"Monochrome"]

OpenersExampleSubsubsection1(Spacer1)Feature Themes  (2)

Use a large graph theme:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotTheme->"LargeGraph"]

Use a classic diagram theme:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},PlotTheme->"ClassicDiagram"]

OpenersExampleSubsection13(Spacer1)Properties  (2)

Specify a property for vertices:

Graph[{1,2,3},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},Properties->{1->{VertexLabels-> "hello"}}]

Edges:

Graph[{1\[DirectedEdge]2,2\[DirectedEdge]3,3\[DirectedEdge]1},Properties->{1\[DirectedEdge]2->{EdgeLabels-> "hello"}}]

OpenersExampleSubsection14(Spacer1)VertexCoordinates  (3)

By default, any vertex coordinates are computed automatically:

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

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:

Graph[Table[i\[UndirectedEdge]Mod[i+1,20,1],{i,20}],VertexCoordinates->ellipseLayout[20,{2,1}]]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexCoordinates->Table[{i,i},{i,3}],GraphLayout->"CircularEmbedding"]

OpenersExampleSubsection15(Spacer1)VertexLabels  (13)

Use vertex names as labels:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->"Name"]

Label individual vertices:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->{2->"one"}]

Label all vertices:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->Table[i->(Subscript[v, i]),{i,3}]]

Use any expression as a label:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->{1->,2->,3->},ImagePadding->30]

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

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■",p],{i,3}],PlotLabel->p],{p,{Before,After,Below,Above}}]

Symbolic outside corner positions:

pl={{Before,Below},{After,Below},{Before,Above},{After,Above}};

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■",p],{i,3}],PlotLabel->p],{p,pl}]

Symbolic inside positions:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.25,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[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.25,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,p],{i,3}],PlotLabel->p],{p,pl}]

Use explicit coordinates to place the center of labels:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.25,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,p],{i,3}],PlotLabel->p,BaselinePosition->Axis],{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[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.35,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,{{1,1},p}],{i,3}],PlotLabel->p,BaselinePosition->Axis],{p,{{0,0},{1/2,1/2},{1,1}}}]

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

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

Any number of labels can be used:

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

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

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

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->Placed["Name",Tooltip]]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->Placed["Name",StatusArea]]

Use more elaborate formatting functions:

rotateLabel[lbl_]:=Rotate[lbl,45Degree]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->Table[i->Placed["xxx",Below,rotateLabel],{i,3}]]

panelLabel[lbl_]:=Panel[lbl,FrameMargins->0,Background->Lighter[Yellow,0.7]]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->Table[i->Placed["xxx",Center,panelLabel],{i,3}]]

hyperlinkLabel[lbl_]:=Hyperlink[lbl,"http://www.wolfram.com"]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexLabels->Table[i->Placed["xxx",Center,hyperlinkLabel],{i,3}]]

OpenersExampleSubsection16(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[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShape->s,VertexSize->Medium],{s,{,,}}]

Specify vertex shapes for individual vertices:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShape->{2->},VertexSize->Medium]

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

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,VertexShape->,PlotLabel->s],{s,{Small,Large}}]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexShape->,VertexStyle->Blue]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.1,VertexShapeFunction->"Square",VertexShape->]

OpenersExampleSubsection17(Spacer1)VertexShapeFunction  (11)

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

GraphElementData["VertexShapeFunction"]

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

GraphElementData["VertexShapeFunction","Basic"]

Simple basic shapes:

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

Common basic shapes:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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["VertexShapeFunction","Rounded"]

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->Style[vf,9]],{vf,GraphElementData["VertexShapeFunction","Rounded"]}]

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

GraphElementData["VertexShapeFunction","Concave"]

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

Draw individual vertices:

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

Combine with a default vertex function:

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

Draw vertices using a predefined graphic:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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}}]
];

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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}]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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}]}

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->"Star",VertexSize->{1->Small,Medium}]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.3,VertexShapeFunction->"Star",VertexShape->]

OpenersExampleSubsection18(Spacer1)VertexSize  (8)

By default, the size of vertices is computed automatically:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->Automatic]

Specify the size of all vertices using symbolic vertex size:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Use a fraction of the minimum distance between vertex coordinates:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,PlotLabel->s],{s,0.1,1,0.3}]

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

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->{"Scaled", s},PlotLabel->{"Scaled", s}],{s,0.1,1,0.3}]

Specify size in both the x and y directions:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,PlotLabel->s],{s,{{0.1,0.2},{0.2,0.1}}}]

Specify the size for individual vertices:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->{1->0.2,2->0.3}]

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

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->s,VertexShape->,PlotLabel->s],{s,{0.1,0.2,0.4}}]

OpenersExampleSubsection19(Spacer1)VertexStyle  (5)

Style all vertices:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->style,VertexSize->0.2],{style,{Yellow,EdgeForm[Dashed]}}]

Style individual vertices:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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}]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},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}]}

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->LightBlue,BaseStyle->EdgeForm[Dotted],VertexSize->0.2]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexStyle->LightBlue,BaseStyle->Gray,VertexSize->0.2]

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

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexShape->,VertexStyle->Blue]

OpenersExampleSubsection20(Spacer1)VertexWeight  (2)

Set the weight for all vertices:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexWeight->{2,3,4}]

PropertyValue[{%,1},VertexWeight]

Use any numeric expression as a weight:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexWeight->{a,b,c}]

PropertyValue[{%,1},VertexWeight]

OpenersExampleSection3(Spacer1)Applications  (4)

Build a graph of a finite mapping:

Graph[Table[i->Mod[(i^2),74],{i,100}]]

Draw the graph of a random permutation:

Graph[Thread[Range[20]->RandomSample[Range[20]]]]

Use (RefLink[Table, paclet:ref/Table]) to set similar properties for many items:

Graph[Table[Property[v,{VertexSize->0.2+0.2Mod[v,5],VertexStyle->Hue[(v/15),1,1]}],{v,0,14}],Table[v\[UndirectedEdge]Mod[v+1,15],{v,0,14}]]

Generate a network of "nearby" words in a dictionary:

words=DictionaryLookup["wol*"];

Flatten[Map[(Thread[#\[DirectedEdge]DeleteCases[Nearest[words,#,3],#]])&,words]];

Graph[%,VertexLabels->"Name",ImageSize->450]

OpenersExampleSection4(Spacer1)Properties & Relations  (3)

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

g=Graph[Table[i\[UndirectedEdge]Mod[i+1,2],{i,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=Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1}];

{VertexList[g],EdgeList[g]}

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

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

{VertexList[g1],EdgeList[g1]}

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

{VertexList[g2],EdgeList[g2]}

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

g=Graph[{a\[DirectedEdge]b,b\[DirectedEdge]c,c\[DirectedEdge]a}];

(m=AdjacencyMatrix[g]//Normal)//MatrixForm

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

VertexList[g]

Position[m,1,{2}]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

(RefLink[Graph, paclet:ref/Graph]) objects are atomic raw objects:

g=Graph[{1->2,2->3,3-> 1}];

AtomQ[g]

Use (RefLink[GraphQ, paclet:ref/GraphQ]) to test whether it is a graph:

MatchQ[g,_?GraphQ]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[TreeGraph, paclet:ref/TreeGraph])  ▪  (RefLink[PathGraph, paclet:ref/PathGraph])  ▪  (RefLink[AdjacencyGraph, paclet:ref/AdjacencyGraph])  ▪  (RefLink[IncidenceGraph, paclet:ref/IncidenceGraph])  ▪  (RefLink[GraphData, paclet:ref/GraphData])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}, {▪(RefLinkPlain[Graph Visualization, paclet:guide/GraphVisualization])}, {▪(RefLinkPlain[Graphs & Networks, paclet:guide/GraphsAndNetworks])}, {▪(RefLinkPlain[Discrete Mathematics, paclet:guide/DiscreteMathematics])}, {▪(RefLinkPlain[Social Network Analysis, paclet:guide/SocialNetworks])}, {▪(RefLinkPlain[WDF (Wolfram Data Framework), paclet:guide/WDFWolframDataFramework])}, {▪(RefLinkPlain[Life Sciences & Medicine: Data & Computation, paclet:guide/LifeSciencesAndMedicineDataAndComputation])}, {▪(RefLinkPlain[Scientific Models, paclet:guide/ScientificModels])}, {▪(RefLinkPlain[Molecular Structure & Computation, paclet:guide/MolecularStructureAndComputation])}, {▪(RefLinkPlain[Scientific Data Analysis, paclet:guide/ScientificDataAnalysis])}, {▪(RefLinkPlain[Database Connectivity, paclet:guide/DatabaseConnectivity])}, {▪(RefLinkPlain[Wolfram Data Repository, paclet:guide/WolframDataRepository])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/21-graphs-and-networks.html])(WebLink[: Graphs and Networks, https://www.wolfram.com/language/elementary-introduction/21-graphs-and-networks.html])}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/30-rearranging-lists.html])(WebLink[: Rearranging Lists, https://www.wolfram.com/language/elementary-introduction/30-rearranging-lists.html])}})}})