AdjacencyGraph
✖
AdjacencyGraph
Details and Options

- AdjacencyGraph[amat] is equivalent to AdjacencyGraph[{1,2,…,n},amat], where amat has dimensions
×
.
- 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 -
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

List of all options




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
column (and, in the case of undirected graphs, the i
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
open allclose allBasic Examples (2)Summary of the most common use cases
Scope (7)Survey of the scope of standard use cases
Symmetric matrices are interpreted as undirected graphs:

https://wolfram.com/xid/08uz06cuvzpizru-ebai8b

Unsymmetric matrices are interpreted as directed graphs:

https://wolfram.com/xid/08uz06cuvzpizru-k6ammb

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

https://wolfram.com/xid/08uz06cuvzpizru-cg39ju

Matrices with diagonal entries create self-loops:

https://wolfram.com/xid/08uz06cuvzpizru-kazbon

Use a SparseArray object to specify the adjacency matrix:

https://wolfram.com/xid/08uz06cuvzpizru-e2qsdd

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

https://wolfram.com/xid/08uz06cuvzpizru-bwfchn

Use an explicit vertex list to give vertex names:

https://wolfram.com/xid/08uz06cuvzpizru-dam920

AdjacencyGraph works with large matrices:

https://wolfram.com/xid/08uz06cuvzpizru-blsdzo


https://wolfram.com/xid/08uz06cuvzpizru-m0c178

Options (83)Common values & functionality for each option
AnnotationRules (3)
Specify an annotation for vertices:

https://wolfram.com/xid/08uz06cuvzpizru-tv6rsi


https://wolfram.com/xid/08uz06cuvzpizru-hfpnz0


https://wolfram.com/xid/08uz06cuvzpizru-wtg2wg


https://wolfram.com/xid/08uz06cuvzpizru-7lc57p

DirectedEdges (3)
By default, a symmetric matrix generates an undirected graph:

https://wolfram.com/xid/08uz06cuvzpizru-k5ap05

Use DirectedEdges->True to generate a directed graph:

https://wolfram.com/xid/08uz06cuvzpizru-c0z931

By default, a nonsymmetric matrix generates a directed graph:

https://wolfram.com/xid/08uz06cuvzpizru-b5w2qe

EdgeLabels (7)

https://wolfram.com/xid/08uz06cuvzpizru-z5279


https://wolfram.com/xid/08uz06cuvzpizru-1t3zd

https://wolfram.com/xid/08uz06cuvzpizru-hr4015

Use any expression as a label:

https://wolfram.com/xid/08uz06cuvzpizru-b7zkda

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

https://wolfram.com/xid/08uz06cuvzpizru-fnltmw

Use explicit coordinates to place labels:

https://wolfram.com/xid/08uz06cuvzpizru-ndfa94

Vary positions within the label:

https://wolfram.com/xid/08uz06cuvzpizru-bg84f5


https://wolfram.com/xid/08uz06cuvzpizru-33q72


https://wolfram.com/xid/08uz06cuvzpizru-hb7fqh

Use automatic labeling by values through Tooltip and StatusArea:

https://wolfram.com/xid/08uz06cuvzpizru-dhn5kr


https://wolfram.com/xid/08uz06cuvzpizru-bd54a9

EdgeShapeFunction (6)
Get a list of built-in settings for EdgeShapeFunction:

https://wolfram.com/xid/08uz06cuvzpizru-hfmhqu

Undirected edges including the basic line:

https://wolfram.com/xid/08uz06cuvzpizru-fjhml

Lines with different glyphs on the edges:

https://wolfram.com/xid/08uz06cuvzpizru-lxjrsx

Directed edges including solid arrows:

https://wolfram.com/xid/08uz06cuvzpizru-lvr0ss


https://wolfram.com/xid/08uz06cuvzpizru-qslbt


https://wolfram.com/xid/08uz06cuvzpizru-f6ch7m

Specify an edge function for an individual edge:

https://wolfram.com/xid/08uz06cuvzpizru-eczrhp

Combine with a different default edge function:

https://wolfram.com/xid/08uz06cuvzpizru-jwjk2c

Draw edges by running a program:

https://wolfram.com/xid/08uz06cuvzpizru-j0dznf

https://wolfram.com/xid/08uz06cuvzpizru-lsgwlp

EdgeShapeFunction can be combined with EdgeStyle:

https://wolfram.com/xid/08uz06cuvzpizru-gt52v9

EdgeShapeFunction has higher priority than EdgeStyle:

https://wolfram.com/xid/08uz06cuvzpizru-cfn5oz

EdgeStyle (2)
EdgeWeight (2)
Specify a weight for all edges:

https://wolfram.com/xid/08uz06cuvzpizru-8fxi6


https://wolfram.com/xid/08uz06cuvzpizru-baprxk

Use any numeric expression as a weight:

https://wolfram.com/xid/08uz06cuvzpizru-bcptub


https://wolfram.com/xid/08uz06cuvzpizru-fibbsw

GraphHighlight (3)
GraphHighlightStyle (2)
Get a list of built-in settings for GraphHighlightStyle:

https://wolfram.com/xid/08uz06cuvzpizru-lu7p68

Use built-in settings for GraphHighlightStyle:

https://wolfram.com/xid/08uz06cuvzpizru-qwjuvn

GraphLayout (5)
By default, the layout is chosen automatically:

https://wolfram.com/xid/08uz06cuvzpizru-o54n3

Specify layouts on special curves:

https://wolfram.com/xid/08uz06cuvzpizru-9n3fm

https://wolfram.com/xid/08uz06cuvzpizru-fstm3e

Specify layouts that satisfy optimality criteria:

https://wolfram.com/xid/08uz06cuvzpizru-bektge

https://wolfram.com/xid/08uz06cuvzpizru-smaaf

VertexCoordinates overrides GraphLayout coordinates:

https://wolfram.com/xid/08uz06cuvzpizru-doiay5

Use AbsoluteOptions to extract VertexCoordinates computed using a layout algorithm:

https://wolfram.com/xid/08uz06cuvzpizru-bdjd2v


https://wolfram.com/xid/08uz06cuvzpizru-duwin9

PlotTheme (4)
Base Themes (2)
VertexCoordinates (3)
By default, any vertex coordinates are computed automatically:

https://wolfram.com/xid/08uz06cuvzpizru-5spor

Extract the resulting vertex coordinates using AbsoluteOptions:

https://wolfram.com/xid/08uz06cuvzpizru-2whoh

Specify a layout function along an ellipse:

https://wolfram.com/xid/08uz06cuvzpizru-mwyuvu

https://wolfram.com/xid/08uz06cuvzpizru-cvx31k

Use it to generate vertex coordinates for a graph:

https://wolfram.com/xid/08uz06cuvzpizru-gssepz

https://wolfram.com/xid/08uz06cuvzpizru-uukkr

VertexCoordinates has higher priority than GraphLayout:

https://wolfram.com/xid/08uz06cuvzpizru-hdij4u

VertexLabels (13)

https://wolfram.com/xid/08uz06cuvzpizru-c9ka50


https://wolfram.com/xid/08uz06cuvzpizru-i40mcj


https://wolfram.com/xid/08uz06cuvzpizru-whkpg

Use any expression as a label:

https://wolfram.com/xid/08uz06cuvzpizru-kokbex

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

https://wolfram.com/xid/08uz06cuvzpizru-csc6y

Symbolic outside corner positions:

https://wolfram.com/xid/08uz06cuvzpizru-405x2

https://wolfram.com/xid/08uz06cuvzpizru-fjgxt8


https://wolfram.com/xid/08uz06cuvzpizru-fg0pin

Symbolic inside corner positions:

https://wolfram.com/xid/08uz06cuvzpizru-kfrv7

https://wolfram.com/xid/08uz06cuvzpizru-dr87wv

Use explicit coordinates to place the center of labels:

https://wolfram.com/xid/08uz06cuvzpizru-cqfi4r

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

https://wolfram.com/xid/08uz06cuvzpizru-20sv


https://wolfram.com/xid/08uz06cuvzpizru-kusfg3

Any number of labels can be used:

https://wolfram.com/xid/08uz06cuvzpizru-fqezh

Use the argument Placed to control formatting including Tooltip:

https://wolfram.com/xid/08uz06cuvzpizru-cxzeiw

Or StatusArea:

https://wolfram.com/xid/08uz06cuvzpizru-nddwmk

Use more elaborate formatting functions:

https://wolfram.com/xid/08uz06cuvzpizru-bd9m40

https://wolfram.com/xid/08uz06cuvzpizru-cggp96


https://wolfram.com/xid/08uz06cuvzpizru-l3s7yb

https://wolfram.com/xid/08uz06cuvzpizru-cljxny


https://wolfram.com/xid/08uz06cuvzpizru-cqkdbb

https://wolfram.com/xid/08uz06cuvzpizru-bjoam1

VertexShape (5)
Use any Graphics, Image, or Graphics3D as a vertex shape:

https://wolfram.com/xid/08uz06cuvzpizru-dvz661

Specify vertex shapes for individual vertices:

https://wolfram.com/xid/08uz06cuvzpizru-i1s9c7

VertexShape can be combined with VertexSize:

https://wolfram.com/xid/08uz06cuvzpizru-jqe83v

VertexShape is not affected by VertexStyle:

https://wolfram.com/xid/08uz06cuvzpizru-3ef8f

VertexShapeFunction has higher priority than VertexShape:

https://wolfram.com/xid/08uz06cuvzpizru-budnxj

VertexShapeFunction (10)
Get a list of built-in collections for VertexShapeFunction:

https://wolfram.com/xid/08uz06cuvzpizru-cc7w4d

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

https://wolfram.com/xid/08uz06cuvzpizru-kqz1mq


https://wolfram.com/xid/08uz06cuvzpizru-hshluc


https://wolfram.com/xid/08uz06cuvzpizru-wm2s7

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

https://wolfram.com/xid/08uz06cuvzpizru-je3pt2


https://wolfram.com/xid/08uz06cuvzpizru-cj5ftp

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

https://wolfram.com/xid/08uz06cuvzpizru-f4ea1p


https://wolfram.com/xid/08uz06cuvzpizru-bfhgv4


https://wolfram.com/xid/08uz06cuvzpizru-fhb0zi

Combine with a default vertex function:

https://wolfram.com/xid/08uz06cuvzpizru-fmawhn

Draw vertices using a predefined graphic:

https://wolfram.com/xid/08uz06cuvzpizru-6fiu

Draw vertices by running a program:

https://wolfram.com/xid/08uz06cuvzpizru-oroxkx

https://wolfram.com/xid/08uz06cuvzpizru-lt54lp

VertexShapeFunction can be combined with VertexStyle:

https://wolfram.com/xid/08uz06cuvzpizru-c5uihz

https://wolfram.com/xid/08uz06cuvzpizru-djz15m

VertexShapeFunction has higher priority than VertexStyle:

https://wolfram.com/xid/08uz06cuvzpizru-h9wrh2

https://wolfram.com/xid/08uz06cuvzpizru-ir0ry

VertexShapeFunction can be combined with VertexSize:

https://wolfram.com/xid/08uz06cuvzpizru-e414xo

VertexShapeFunction has higher priority than VertexShape:

https://wolfram.com/xid/08uz06cuvzpizru-lnnzsy

VertexSize (8)
By default, the size of vertices is computed automatically:

https://wolfram.com/xid/08uz06cuvzpizru-dsy1ve

Specify the size of all vertices using symbolic vertex size:

https://wolfram.com/xid/08uz06cuvzpizru-lskxsr

Use a fraction of the minimum distance between vertex coordinates:

https://wolfram.com/xid/08uz06cuvzpizru-3lxk1

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

https://wolfram.com/xid/08uz06cuvzpizru-my5omo

Specify size in both the and
directions:

https://wolfram.com/xid/08uz06cuvzpizru-c7twgs

Specify the size for individual vertices:

https://wolfram.com/xid/08uz06cuvzpizru-h6r4ja

VertexSize can be combined with VertexShapeFunction:

https://wolfram.com/xid/08uz06cuvzpizru-b3jw4t

VertexSize can be combined with VertexShape:

https://wolfram.com/xid/08uz06cuvzpizru-dego1v

VertexStyle (5)

https://wolfram.com/xid/08uz06cuvzpizru-ehbi7i


https://wolfram.com/xid/08uz06cuvzpizru-dtkst6

VertexShapeFunction can be combined with VertexStyle:

https://wolfram.com/xid/08uz06cuvzpizru-om30z

https://wolfram.com/xid/08uz06cuvzpizru-nnfnwx

VertexShapeFunction has higher priority than VertexStyle:

https://wolfram.com/xid/08uz06cuvzpizru-kfv4n

https://wolfram.com/xid/08uz06cuvzpizru-cldcke

VertexStyle can be combined with BaseStyle:

https://wolfram.com/xid/08uz06cuvzpizru-bby1h9

VertexStyle has higher priority than BaseStyle:

https://wolfram.com/xid/08uz06cuvzpizru-d0df6

VertexShape is not affected by VertexStyle:

https://wolfram.com/xid/08uz06cuvzpizru-3rqw0

VertexWeight (2)
Set the weight for all vertices:

https://wolfram.com/xid/08uz06cuvzpizru-coy9ti


https://wolfram.com/xid/08uz06cuvzpizru-jjkrix

Use any numeric expression as a weight:

https://wolfram.com/xid/08uz06cuvzpizru-lxjpz1


https://wolfram.com/xid/08uz06cuvzpizru-d24c0

Applications (2)Sample problems that can be solved with this function
Construct a graph from a list of sets s where vertex i represents s〚i〛 and has an edge ij if s〚i〛⊆s〚j〛:

https://wolfram.com/xid/08uz06cuvzpizru-tlovp


https://wolfram.com/xid/08uz06cuvzpizru-cgz26v

Construct a graph from a list of integers s where ij if s〚i〛 divides s〚j〛 (s〚i〛∣s〚j〛):

https://wolfram.com/xid/08uz06cuvzpizru-buxeif


https://wolfram.com/xid/08uz06cuvzpizru-fodacq

Properties & Relations (6)Properties of the function, and connections to other functions
Use VertexCount and EdgeCount to count vertices and edges:

https://wolfram.com/xid/08uz06cuvzpizru-ewldet


https://wolfram.com/xid/08uz06cuvzpizru-buy2ca

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

https://wolfram.com/xid/08uz06cuvzpizru-l0u8q


https://wolfram.com/xid/08uz06cuvzpizru-l06m

Compute the AdjacencyMatrix from a graph:

https://wolfram.com/xid/08uz06cuvzpizru-bil8h7

https://wolfram.com/xid/08uz06cuvzpizru-cewi3i

A graph can be reconstructed from its adjacency matrix:

https://wolfram.com/xid/08uz06cuvzpizru-b4da3u


https://wolfram.com/xid/08uz06cuvzpizru-fx57ie

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

https://wolfram.com/xid/08uz06cuvzpizru-9rbvo


https://wolfram.com/xid/08uz06cuvzpizru-lwoun1

Every 1 in the diagonal indicates self-loops:

https://wolfram.com/xid/08uz06cuvzpizru-zsnlc

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

https://wolfram.com/xid/08uz06cuvzpizru-efp5ir

https://wolfram.com/xid/08uz06cuvzpizru-c3wc3


https://wolfram.com/xid/08uz06cuvzpizru-h0grde


https://wolfram.com/xid/08uz06cuvzpizru-egi1k8

Wolfram Research (2010), AdjacencyGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
Text
Wolfram Research (2010), AdjacencyGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
Wolfram Research (2010), AdjacencyGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
CMS
Wolfram Language. 2010. "AdjacencyGraph." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
Wolfram Language. 2010. "AdjacencyGraph." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AdjacencyGraph.html.
APA
Wolfram Language. (2010). AdjacencyGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AdjacencyGraph.html
Wolfram Language. (2010). AdjacencyGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AdjacencyGraph.html
BibTeX
@misc{reference.wolfram_2025_adjacencygraph, author="Wolfram Research", title="{AdjacencyGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/AdjacencyGraph.html}", note=[Accessed: 25-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_adjacencygraph, organization={Wolfram Research}, title={AdjacencyGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/AdjacencyGraph.html}, note=[Accessed: 25-March-2025
]}