---
title: "AdjacencyGraph"
language: "en"
type: "Symbol"
summary: "AdjacencyGraph[amat] gives the graph with adjacency matrix amat. AdjacencyGraph[{v1, v2, ...}, amat] gives the graph with vertices vi and adjacency matrix amat."
keywords: 
- adjacency matrix graph
- graph from adjacency matrix
- vertex-vertex connectivity graph
- node-node connectivity graph
- matrix graph
- matrix graph constructor
- sociomatrix
- sociogram
canonical_url: "https://reference.wolfram.com/language/ref/AdjacencyGraph.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graphs and Matrices"
    link: "https://reference.wolfram.com/language/guide/GraphsAndMatrices.en.md"
  - 
    title: "Graph Construction & Representation"
    link: "https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md"
  - 
    title: "Graph Programming"
    link: "https://reference.wolfram.com/language/guide/GraphProgramming.en.md"
  - 
    title: "Graphs & Networks"
    link: "https://reference.wolfram.com/language/guide/GraphsAndNetworks.en.md"
---
# AdjacencyGraph

AdjacencyGraph[amat] gives the graph with adjacency matrix amat.

AdjacencyGraph[{v1, v2, …}, amat] gives the graph with vertices vi and adjacency matrix amat.

## Details and Options

[image]

* ``AdjacencyGraph[amat]`` is equivalent to ``AdjacencyGraph[{1, 2, …, n}, amat]``, where ``amat`` has dimensions $n$×$n$.

* ``AdjacencyGraph`` takes the same options as ``Graph``.

* The option ``DirectedEdges`` can be used to control whether an undirected or directed graph is constructed.

* The following settings for ``DirectedEdges`` can be used in ``AdjacencyGraph`` :

|           |                                       |
| --------- | ------------------------------------- |
| Automatic | undirected graph if amat is symmetric |
| True      | construct a directed graph            |
| False     | construct an undirected graph         |

### List of all options

|                        |                 |                                                                                    |
| ---------------------- | --------------- | ---------------------------------------------------------------------------------- |
| AlignmentPoint         | Center          | the default point in the graphic to align with                                     |
| AnnotationRules        | {}              | annotations for graph, edges and vertices                                          |
| AspectRatio            | Automatic       | ratio of height to width                                                           |
| Axes                   | False           | whether to draw axes                                                               |
| AxesLabel              | None            | axes labels                                                                        |
| AxesOrigin             | Automatic       | where axes should cross                                                            |
| AxesStyle              | {}              | style specifications for the axes                                                  |
| Background             | None            | background color for the plot                                                      |
| BaselinePosition       | Automatic       | how to align with a surrounding text baseline                                      |
| BaseStyle              | {}              | base style specifications for the graphic                                          |
| ContentSelectable      | Automatic       | whether to allow contents to be selected                                           |
| CoordinatesToolOptions | Automatic       | detailed behavior of the coordinates tool                                          |
| DirectedEdges          | Automatic       | whether to interpret Rule as DirectedEdge                                          |
| EdgeLabels             | None            | labels and label placements for edges                                              |
| EdgeLabelStyle         | Automatic       | style to use for edge labels                                                       |
| EdgeShapeFunction      | Automatic       | generate graphic shapes for edges                                                  |
| EdgeStyle              | Automatic       | style used for edges                                                               |
| EdgeWeight             | Automatic       | weights for edges                                                                  |
| Epilog                 | {}              | primitives rendered after the main plot                                            |
| FormatType             | TraditionalForm | the default format type for text                                                   |
| Frame                  | False           | whether to put a frame around the plot                                             |
| FrameLabel             | None            | frame labels                                                                       |
| FrameStyle             | {}              | style specifications for the frame                                                 |
| FrameTicks             | Automatic       | frame ticks                                                                        |
| FrameTicksStyle        | {}              | style specifications for frame ticks                                               |
| GraphHighlight         | {}              | graph elements to highlight                                                        |
| GraphHighlightStyle    | Automatic       | style for highlight                                                                |
| GraphLayout            | Automatic       | how to lay out vertices and edges                                                  |
| GridLines              | None            | grid lines to draw                                                                 |
| GridLinesStyle         | {}              | style specifications for grid lines                                                |
| ImageMargins           | 0.              | the margins to leave around the graphic                                            |
| ImagePadding           | All             | what extra padding to allow for labels etc.                                        |
| ImageSize              | Automatic       | the absolute size at which to render the graphic                                   |
| LabelStyle             | {}              | style specifications for labels                                                    |
| Method                 | Automatic       | details of graphics methods to use                                                 |
| PerformanceGoal        | Automatic       | aspects of performance to try to optimize                                          |
| PlotLabel              | None            | an overall label for the plot                                                      |
| PlotRange              | All             | range of values to include                                                         |
| PlotRangeClipping      | False           | whether to clip at the plot range                                                  |
| PlotRangePadding       | Automatic       | how much to pad the range of values                                                |
| PlotRegion             | Automatic       | the final display region to be filled                                              |
| PlotTheme              | \$PlotTheme     | overall theme for the graph                                                        |
| PreserveImageOptions   | Automatic       | whether to preserve image options when displaying new versions of the same graphic |
| Prolog                 | {}              | primitives rendered before the main plot                                           |
| RotateLabel            | True            | whether to rotate y labels on the frame                                            |
| Ticks                  | Automatic       | axes ticks                                                                         |
| TicksStyle             | {}              | style specifications for axes ticks                                                |
| VertexCoordinates      | Automatic       | coordinates for vertices                                                           |
| VertexLabels           | None            | labels and placements for vertices                                                 |
| VertexLabelStyle       | Automatic       | style to use for vertex labels                                                     |
| VertexShape            | Automatic       | graphic shape for vertices                                                         |
| VertexShapeFunction    | Automatic       | generate graphic shapes for vertices                                               |
| VertexSize             | Medium          | size of vertices                                                                   |
| VertexStyle            | Automatic       | styles for vertices                                                                |
| VertexWeight           | Automatic       | weights for vertices                                                               |

---

## Background & Context

``AdjacencyGraph`` constructs a graph from an adjacency matrix representation of an undirected or directed graph. An adjacency matrix is a square matrix whose rows and columns correspond to the vertices of a graph and whose elements ``aij`` are non-negative integers that give the numbers of (directed) edges from vertex ``vi`` to vertex ``vj``. Adjacency matrices with diagonal entries create self-loops.

The option ``DirectedEdges`` (with possible values ``Automatic``, ``True``, or ``False``) may be used to control whether an undirected or directed graph is constructed. By default, ``AdjacencyGraph`` returns an undirected graph if the input matrix is symmetric and a directed graph otherwise.

``AdjacencyGraph`` takes the same options as ``Graph`` (e.g. ``EdgeStyle``, ``VertexStyle``, ``EdgeLabels``, ``VertexLabels``, ``GraphLayout``, ``VertexCoordinates``, etc.). ``AdjacencyGraph`` does not take graph weights into account, so ``WeightedAdjacencyGraph`` must be used when constructing a graph from a weighted adjacency matrix.

``AdjacencyList`` returns a list of vertices adjacent to a given vertex ``vi`` and therefore corresponds to a list of the positions of nonzero elements in the ``i``$$^{\text{th}}$$ column (and, in the case of undirected graphs, the ``i``$$^{\text{th}}$$ row) of the adjacency matrix. The entire adjacency matrix of any graph (including a graph constructed using ``AdjacencyGraph``) may be returned using ``AdjacencyMatrix``. ``IncidenceGraph`` uses an incidence matrix representation instead of an adjacency matrix to construct a graph.

---

## Examples (100)

### Basic Examples (2)

Construct a graph from an adjacency matrix:

```wl
In[1]:= AdjacencyGraph[{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}]

Out[1]= [image]
```

---

A symmetric adjacency matrix results in an undirected graph:

```wl
In[1]:= AdjacencyGraph[{{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}]

Out[1]= [image]
```

### Scope (7)

Symmetric matrices are interpreted as undirected graphs:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |   |
| - | - | - | - |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)]

Out[1]= [image]
```

---

Unsymmetric matrices are interpreted as directed graphs:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |   |
| - | - | - | - |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 |)]

Out[1]= [image]
```

---

Use ``DirectedEdges`` to construct a directed graph from a symmetric matrix:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |   |
| - | - | - | - |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |), DirectedEdges -> True]

Out[1]= [image]
```

---

Matrices with diagonal entries create self-loops:

```wl
In[1]:=
{AdjacencyGraph[(|   |   |   |   |
| - | - | - | - |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)], AdjacencyGraph[(|   |   |   |   |
| - | - | - | - |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 |)]}

Out[1]= {[image], [image]}
```

---

Use a ``SparseArray`` object to specify the adjacency matrix:

```wl
In[1]:= AdjacencyGraph[SparseArray[{{i_, j_} /; 0 < Abs[i - j] ≤ 3 -> 1}, {6, 6}]]

Out[1]= [image]
```

---

By default, the vertices are taken to be the integers 1 through $n$:

```wl
In[1]:=
VertexList@AdjacencyGraph[(|   |   |   |   |
| - | - | - | - |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)]

Out[1]= {1, 2, 3, 4}
```

Use an explicit vertex list to give vertex names:

```wl
In[2]:=
VertexList@AdjacencyGraph[{a, b, c, d}, (|   |   |   |   |
| - | - | - | - |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |)]

Out[2]= {a, b, c, d}
```

---

``AdjacencyGraph`` works with large matrices:

```wl
In[1]:= SparseArray[{Band[{2, 1}] -> 1, Band[{3, 1}] -> 1}, {10^6, 10^6}]

Out[1]= SparseArray[<1999997>, {1000000, 1000000}]

In[2]:= Timing[AdjacencyGraph[%]//EdgeCount]

Out[2]= {1.27435, 1999997}
```

### Options (83)

#### AnnotationRules (3)

Specify an annotation for vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), AnnotationRules -> {3 -> {VertexLabels -> "hello"}}]

Out[1]= [image]
```

---

Edges:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), AnnotationRules -> {1\[UndirectedEdge]2 -> {EdgeLabels -> "hello"}}]

Out[1]= [image]
```

---

Graph itself:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]

Out[1]= [image]

In[2]:= AnnotationValue[%, "Message"]

Out[2]= "hello"
```

#### DirectedEdges (3)

By default, a symmetric matrix generates an undirected graph:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |   |   |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |)]

Out[1]= [image]
```

---

Use ``DirectedEdges -> True`` to generate a directed graph:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |   |   |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |), DirectedEdges -> True, EdgeStyle -> Arrowheads[Medium]]

Out[1]= [image]
```

---

By default, a nonsymmetric matrix generates a directed graph:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |   |   |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |)]

Out[1]= [image]
```

#### EdgeLabels (7)

Label the edge ``1\[UndirectedEdge]2``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {1\[UndirectedEdge]2 -> "Hello"}]

Out[1]= [image]
```

---

Label all edges individually:

```wl
In[1]:= el = {1\[UndirectedEdge]2, 1\[UndirectedEdge]3, 2\[UndirectedEdge]3};

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]

Out[2]= [image]
```

---

Use any expression as a label:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {1\[UndirectedEdge]2 -> [image], 2\[UndirectedEdge]3 -> [image], 1\[UndirectedEdge]3 -> [image]}]

Out[1]= [image]
```

---

Use ``Placed`` with symbolic locations to control label placement along an edge:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {1\[UndirectedEdge]2 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]

Out[1]= {[image], [image], [image]}
```

---

Use explicit coordinates to place labels:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {1\[UndirectedEdge]2 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]

Out[1]= {[image], [image], [image]}
```

Vary positions within the label:

```wl
In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {1\[UndirectedEdge]2 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[2]= {[image], [image], [image]}
```

---

Place multiple labels:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {3\[UndirectedEdge]1 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]

Out[1]= [image]

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> {3\[UndirectedEdge]1 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]

Out[2]= [image]
```

---

Use automatic labeling by values through ``Tooltip`` and ``StatusArea``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> Placed["Name", Tooltip]]

Out[1]= [image]

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeLabels -> Placed["Name", StatusArea]]

Out[2]= [image]
```

#### EdgeShapeFunction (6)

Get a list of built-in settings for ``EdgeShapeFunction``:

```wl
In[1]:= ResourceData["EdgeShapeFunction"]

Out[1]= {"Arrow", "BoxLine", "CarvedArcArrow", "CarvedArrow", "DashedLine", "DiamondLine", "DotLine", "DottedLine", "FilledArcArrow", "FilledArrow", "HalfFilledArrow", "HalfFilledDoubleArrow", "HalfUnfilledArrow", "HalfUnfilledDoubleArrow", "Line", "ShortCarvedArcArrow", "ShortCarvedArrow", "ShortFilledArcArrow", "ShortFilledArrow", "ShortUnfilledArcArrow", "ShortUnfilledArrow", "UnfilledArcArrow", "UnfilledArrow"}
```

---

Undirected edges including the basic line:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeShapeFunction -> "Line"]

Out[1]= [image]
```

Lines with different glyphs on the edges:

```wl
In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]

Out[2]= {[image], [image], [image]}
```

---

Directed edges including solid arrows:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]

Out[1]= {[image], [image], [image], [image], [image], [image]}
```

Line arrows:

```wl
In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Open arrows:

```wl
In[3]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]

Out[3]= {[image], [image], [image], [image]}
```

---

Specify an edge function for an individual edge:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {1\[DirectedEdge]2 -> "FilledArcArrow"}]

Out[1]= [image]
```

Combine with a different default edge function:

```wl
In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |), EdgeShapeFunction -> {1\[DirectedEdge]2 -> "FilledArcArrow", "CarvedArrow"}]

Out[2]= [image]
```

---

Draw edges by running a program:

```wl
In[1]:=
ef[pts_List, e_] := 
	Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeShapeFunction -> ef]

Out[2]= [image]
```

---

``EdgeShapeFunction`` can be combined with ``EdgeStyle``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]

Out[1]= [image]
```

``EdgeShapeFunction`` has higher priority than ``EdgeStyle``:

```wl
In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]

Out[2]= [image]
```

#### EdgeStyle (2)

Style all edges:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> style, PlotLabel -> style], {style, {Gray, Dashed, Thick}}]

Out[1]= {[image], [image], [image]}
```

---

Style individual edges:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeStyle -> {1\[UndirectedEdge]2 -> Blue, 1\[UndirectedEdge]3 -> Dashed}]

Out[1]= [image]
```

#### EdgeWeight (2)

Specify a weight for all edges:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeWeight -> RandomInteger[5, 3]]

Out[1]= [image]

In[2]:= WeightedAdjacencyMatrix[%]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |
| - | - | - |
| 0 | 4 | 2 |
| 4 | 0 | 4 |
| 2 | 4 | 0 |⁠)
```

---

Use any numeric expression as a weight:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), EdgeWeight -> {a, b, c}]

Out[1]= [image]

In[2]:= WeightedAdjacencyMatrix[%]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |
| - | - | - |
| 0 | a | b |
| a | 0 | c |
| b | c | 0 |⁠)
```

#### GraphHighlight (3)

Highlight the vertex ``1`` :

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Tiny, GraphHighlight -> {1}]

Out[1]= [image]
```

---

Highlight the edge ``2\[UndirectedEdge]3`` :

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Tiny, GraphHighlight -> {2\[UndirectedEdge]3}]

Out[1]= [image]
```

---

Highlight vertices and edges:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Tiny, GraphHighlight -> {1, 2, 2\[UndirectedEdge]3}]

Out[1]= [image]
```

#### GraphHighlightStyle (2)

Get a list of built-in settings for ``GraphHighlightStyle``:

```wl
In[1]:= ResourceData["GraphHighlightStyle"]

Out[1]= {Automatic, "Dashed", "Dotted", "Thick", "VertexConcaveDiamond", "VertexDiamond", "VertexTriangle", "DehighlightFade", "DehighlightGray", "DehighlightHide"}
```

---

Use built-in settings for ``GraphHighlightStyle`` :

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphHighlight -> {1, 2\[UndirectedEdge]3}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]

Out[1]= {[image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

#### GraphLayout (5)

By default, the layout is chosen automatically:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphLayout -> Automatic]

Out[1]= [image]
```

---

Specify layouts on special curves:

```wl
In[1]:= m = AdjacencyMatrix[GridGraph[{10, 10}]];

In[2]:= Table[AdjacencyGraph[m, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]

Out[2]= {[image], [image]}
```

---

Specify layouts that satisfy optimality criteria:

```wl
In[1]:= m = AdjacencyMatrix[GridGraph[{10, 10}]];

In[2]:= Table[AdjacencyGraph[m, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]

Out[2]= {[image], [image], [image]}
```

---

``VertexCoordinates`` overrides ``GraphLayout`` coordinates:

```wl
In[1]:=
{AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphLayout -> "SpringElectricalEmbedding"], 
	AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 2}]]}

Out[1]= {[image], [image]}
```

---

Use ``AbsoluteOptions`` to extract ``VertexCoordinates`` computed using a layout algorithm:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |)]

Out[1]= [image]

In[2]:= AbsoluteOptions[%, VertexCoordinates]

Out[2]= {VertexCoordinates -> {{-0.866025, -0.5}, {0.866025, -0.5}, {1.8369701987210297`*^-16, 1.}}}
```

#### PlotTheme (4)

##### Base Themes (2)

Use a common base theme:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), PlotTheme -> "Business"]

Out[1]= [image]
```

---

Use a monochrome theme:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), PlotTheme -> "Monochrome"]

Out[1]= [image]
```

##### Feature Themes (2)

Use a large graph theme:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), PlotTheme -> "LargeGraph"]

Out[1]= [image]
```

---

Use a classic diagram theme:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), PlotTheme -> "ClassicDiagram"]

Out[1]= [image]
```

#### VertexCoordinates (3)

By default, any vertex coordinates are computed automatically:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |)]

Out[1]= [image]
```

Extract the resulting vertex coordinates using ``AbsoluteOptions``:

```wl
In[2]:= AbsoluteOptions[%, VertexCoordinates]

Out[2]= {VertexCoordinates -> {{-0.866025, -0.5}, {0.866025, -0.5}, {1.8369701987210297`*^-16, 1.}}}
```

---

Specify a layout function along an ellipse:

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

In[2]:= Graphics[Point[ellipseLayout[20, {2, 1}]]]

Out[2]= [image]
```

Use it to generate vertex coordinates for a graph:

```wl
In[3]:= m = AdjacencyMatrix[PathGraph[Range[20]]];

In[4]:= AdjacencyGraph[m, VertexCoordinates -> ellipseLayout[20, {2, 1}]]

Out[4]= [image]
```

---

``VertexCoordinates`` has higher priority than ``GraphLayout`` :

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexCoordinates -> Table[{i, i}, {i, 3}], GraphLayout -> "CircularEmbedding"]

Out[1]= [image]
```

#### VertexLabels (13)

Use vertex names as labels:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> "Name"]

Out[1]= [image]
```

---

Label individual vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {1 -> "one"}]

Out[1]= [image]
```

---

Label all vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Subscript[v, i], {i, 3}]]

Out[1]= [image]
```

---

Use any expression as a label:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 30]

Out[1]= [image]
```

---

Use ``Placed`` with symbolic locations to control label placement, including outside positions:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Symbolic outside corner positions:

```wl
In[1]:= pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};

In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]

Out[2]= {[image], [image], [image], [image]}
```

---

Symbolic inside positions:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.25, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Symbolic inside corner positions:

```wl
In[1]:= pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};

In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]

Out[2]= {[image], [image], [image], [image]}
```

---

Use explicit coordinates to place the center of labels:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[1]= {[image], [image], [image]}
```

---

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

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.35, 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}}}]

Out[1]= {[image], [image], [image]}
```

---

Place multiple labels:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {3 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]

Out[1]= [image]
```

Any number of labels can be used:

```wl
In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> {3 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]

Out[2]= [image]
```

---

Use the argument ``Placed`` to control formatting including ``Tooltip``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Placed["Name", Tooltip]]

Out[1]= [image]
```

Or ``StatusArea``:

```wl
In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Placed["Name", StatusArea]]

Out[2]= [image]
```

---

Use more elaborate formatting functions:

```wl
In[1]:= rotateLabel[lab_] := Rotate[lab, 45Degree]

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 3}]]

Out[2]= [image]

In[3]:= panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]

In[4]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 3}]]

Out[4]= [image]

In[5]:= hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]

In[6]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 3}]]

Out[6]= [image]
```

#### VertexShape (5)

Use any ``Graphics``, ``Image``, or ``Graphics3D`` as a vertex shape:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]

Out[1]= {[image], [image], [image]}
```

---

Specify vertex shapes for individual vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShape -> {2 -> [image]}, VertexSize -> Small]

Out[1]= [image]
```

---

``VertexShape`` can be combined with ``VertexSize``:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]

Out[1]= {[image], [image]}
```

---

``VertexShape`` is not affected by ``VertexStyle``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]

Out[1]= [image]
```

---

``VertexShapeFunction`` has higher priority than ``VertexShape`` :

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexShapeFunction -> "Square", VertexShape -> [image]]

Out[1]= [image]
```

#### VertexShapeFunction (10)

Get a list of built-in collections for ``VertexShapeFunction``:

```wl
In[1]:= ResourceData["VertexShapeFunction"]

Out[1]= {"Capsule", "Circle", "ConcaveDiamond", "ConcaveHexagon", "ConcavePentagon", "ConcaveSquare", "ConcaveTriangle", "Diamond", "DownTrapezoid", "FiveDown", "Hexagon", "Octagon", "Parallelogram", "Pentagon", "Point", "Rectangle", "RoundedDiamond", "RoundedDownTrapezoid", "RoundedFiveDown", "RoundedHexagon", "RoundedParallelogram", "RoundedPentagon", "RoundedRectangle", "RoundedSquare", "RoundedTriangle", "RoundedUpTrapezoid", "Square", "Star", "Triangle", "UpTrapezoid"}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Basic"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Basic"]

Out[1]= {"Capsule", "Circle", "Diamond", "DownTrapezoid", "FiveDown", "Hexagon", "Octagon", "Parallelogram", "Pentagon", "Point", "Rectangle", "Square", "Star", "Triangle", "UpTrapezoid"}
```

Simple basic shapes:

```wl
In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Common basic shapes:

```wl
In[3]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]

Out[3]= {[image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Rounded"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Rounded"]

Out[1]= {"RoundedDiamond", "RoundedDownTrapezoid", "RoundedFiveDown", "RoundedHexagon", "RoundedParallelogram", "RoundedPentagon", "RoundedRectangle", "RoundedSquare", "RoundedTriangle", "RoundedUpTrapezoid"}

In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]

Out[2]= {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Concave"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Concave"]

Out[1]= {"ConcaveDiamond", "ConcaveHexagon", "ConcavePentagon", "ConcaveSquare", "ConcaveTriangle"}

In[2]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]

Out[2]= {[image], [image], [image], [image], [image]}
```

---

Draw individual vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]

Out[1]= [image]
```

Combine with a default vertex function:

```wl
In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]

Out[2]= [image]
```

---

Draw vertices using a predefined graphic:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> (Inset[[image], #]&)]

Out[1]= [image]
```

---

Draw vertices by running a program:

```wl
In[1]:=
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}}]
	];

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> vf, VertexSize -> 0.2]

Out[2]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexStyle``:

```wl
In[1]:= vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]

Out[2]= [image]
```

``VertexShapeFunction`` has higher priority than ``VertexStyle``:

```wl
In[3]:= vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}

In[4]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]

Out[4]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexSize``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]

Out[1]= [image]
```

---

``VertexShapeFunction`` has higher priority than ``VertexShape``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]

Out[1]= [image]
```

#### VertexSize (8)

By default, the size of vertices is computed automatically:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> Automatic]

Out[1]= [image]
```

---

Specify the size of all vertices using symbolic vertex size:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Use a fraction of the minimum distance between vertex coordinates:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]

Out[1]= {[image], [image], [image], [image]}
```

---

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

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]

Out[1]= {[image], [image], [image], [image]}
```

---

Specify size in both the $x$ and $y$ directions:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]

Out[1]= {[image], [image]}
```

---

Specify the size for individual vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> {1 -> 0.2, 2 -> 0.3}]

Out[1]= [image]
```

---

``VertexSize`` can be combined with ``VertexShapeFunction`` :

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]

Out[1]= {[image], [image], [image]}
```

---

``VertexSize`` can be combined with ``VertexShape`` :

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]

Out[1]= {[image], [image], [image]}
```

#### VertexStyle (5)

Style all vertices:

```wl
In[1]:=
Table[AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]

Out[1]= {[image], [image]}
```

---

Style individual vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> {1 -> Blue, 2 -> Red}, VertexSize -> 0.2]

Out[1]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexStyle``:

```wl
In[1]:= vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]

In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]

Out[2]= [image]
```

``VertexShapeFunction`` has higher priority than ``VertexStyle``:

```wl
In[3]:= vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}

In[4]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]

Out[4]= [image]
```

---

``VertexStyle`` can be combined with ``BaseStyle``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]

Out[1]= [image]
```

``VertexStyle`` has higher priority than ``BaseStyle``:

```wl
In[2]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]

Out[2]= [image]
```

---

``VertexShape`` is not affected by ``VertexStyle``:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]

Out[1]= [image]
```

#### VertexWeight (2)

Set the weight for all vertices:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexWeight -> {2, 3, 4}]

Out[1]= [image]

In[2]:= AnnotationValue[{%, 1}, VertexWeight]

Out[2]= 2
```

---

Use any numeric expression as a weight:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |), VertexWeight -> {a, b, c}]

Out[1]= [image]

In[2]:= AnnotationValue[{%, 1}, VertexWeight]

Out[2]= a
```

### Applications (2)

Construct a graph from a list of sets ``s`` where vertex ``i`` represents ``s[[i]]`` and has an edge ``i\[DirectedEdge]j`` if ``s[[i]]⊆s[[j]]``:

```wl
In[1]:= s = Subsets[{1, 2, 3}]

Out[1]= {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}

In[2]:= AdjacencyGraph[s, Table[Boole@SubsetQ[s[[i]], s[[j]]], {i, Length[s]}, {j, Length[s]}], VertexLabels -> "Name"]

Out[2]= [image]
```

---

Construct a graph from a list of integers ``s`` where ``i\[DirectedEdge]j`` if ``s[[i]]`` divides ``s[[j]]`` (``s[[i]]∣s[[j]]``):

```wl
In[1]:= s = Divisors[24]

Out[1]= {1, 2, 3, 4, 6, 8, 12, 24}

In[2]:= AdjacencyGraph[s, Table[Boole@Divisible[s[[i]], s[[j]]], {i, Length[s]}, {j, Length[s]}], VertexLabels -> "Name"]

Out[2]= [image]
```

### Properties & Relations (6)

Use ``VertexCount`` and ``EdgeCount`` to count vertices and edges:

```wl
In[1]:=
g = AdjacencyGraph[(|   |   |   |   |   |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |)]

Out[1]= [image]

In[2]:= {VertexCount[g], EdgeCount[g]}

Out[2]= {5, 10}
```

---

Use ``VertexList`` and ``EdgeList`` to enumerate vertices and edges in standard order:

```wl
In[1]:=
g = AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |)]

Out[1]= [image]

In[2]:= {VertexList[g], EdgeList[g]}

Out[2]= {{1, 2, 3}, {1\[DirectedEdge]2, 2\[DirectedEdge]3, 3\[DirectedEdge]1}}
```

---

Compute the ``AdjacencyMatrix`` from a graph:

```wl
In[1]:=
g = AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |)];

In[2]:= AdjacencyMatrix[g]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |⁠)
```

---

A graph can be reconstructed from its adjacency matrix:

```wl
In[1]:= CompleteGraph[5]

Out[1]= [image]

In[2]:= AdjacencyGraph [AdjacencyMatrix[%]]

Out[2]= [image]
```

---

An adjacency matrix with all zero entries in the diagonal constructs a graph without self-loops:

```wl
In[1]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |)]

Out[1]= [image]

In[2]:= LoopFreeGraphQ[%]

Out[2]= True
```

Every 1 in the diagonal indicates self-loops:

```wl
In[3]:=
AdjacencyGraph[(|   |   |   |
| - | - | - |
| 1 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |)]

Out[3]= [image]
```

---

An adjacency matrix whose entries outside the diagonal are all 1s constructs a complete graph:

```wl
In[1]:=
m = (|   |   |   |   |   |
| - | - | - | - | - |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |);

In[2]:= MatrixPlot[m]

Out[2]= [image]

In[3]:= AdjacencyGraph[m]

Out[3]= [image]

In[4]:= CompleteGraphQ[%]

Out[4]= True
```

## See Also

* [`AdjacencyMatrix`](https://reference.wolfram.com/language/ref/AdjacencyMatrix.en.md)
* [`WeightedAdjacencyGraph`](https://reference.wolfram.com/language/ref/WeightedAdjacencyGraph.en.md)
* [`IncidenceGraph`](https://reference.wolfram.com/language/ref/IncidenceGraph.en.md)
* [`KirchhoffGraph`](https://reference.wolfram.com/language/ref/KirchhoffGraph.en.md)
* [`Graph`](https://reference.wolfram.com/language/ref/entity/Graph.en.md)
* [`Graph`](https://reference.wolfram.com/language/ref/interpreter/Graph.en.md)

## Related Guides

* [Graphs and Matrices](https://reference.wolfram.com/language/guide/GraphsAndMatrices.en.md)
* [Graph Construction & Representation](https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md)
* [Graph Programming](https://reference.wolfram.com/language/guide/GraphProgramming.en.md)
* [Graphs & Networks](https://reference.wolfram.com/language/guide/GraphsAndNetworks.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Graphs and Networks](https://www.wolfram.com/language/elementary-introduction/21-graphs-and-networks.html)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md)