Graph Representation and Properties

Graphs are first-class citizens in Mathematica, and can be used as input, output, in programs, and in documents. Undirected and directed graphs are treated uniformly and support a number of standard properties for vertices and edges. Importantly, graphs also support custom properties for modeling or computational flexibility. Graphs can be converted to a number of different representations, including matrices. Graphs can be exported with high-fidelity to numerous file formats.

ReferenceReference

Graph represent a general graph, or create it from vertices and edges

UndirectedEdge an undirected edge (UndirectedEdge)

DirectedEdge a directed edge (DirectedEdge)

GraphQ ▪ UndirectedGraphQ ▪ DirectedGraphQ ▪ EdgeQ ▪ VertexQ

Basic Properties

VertexCount, EdgeCount the number of vertices and edges in the graph

VertexList, EdgeList the list of vertices and edges in the graph

VertexIndex, EdgeIndex the index for a vertex or edge in a graph

EdgeRules the list of edges as a list of rules

Standard Properties

EdgeShapeFunction, EdgeStyle, EdgeLabels render, style, and label edges

VertexShapeFunction, VertexStyle, VertexLabels render, style, and label vertices

GraphLayout, GraphStyle, GraphHighlightStyle layout, style, and highlight graphs

EdgeWeight ▪ EdgeCapacity ▪ VertexShape ▪ VertexWeight ▪ VertexCapacity ▪ VertexCoordinates ▪ VertexSize ▪ GraphHighlight

Custom Properties »

Property property wrapper for vertices and edges

PropertyValue get and set vertex or edge property values

PropertyList ▪ SetProperty ▪ RemoveProperty ▪ Properties

Matrix Representations »

AdjacencyMatrix vertex-vertex adjacency matrix

IncidenceMatrix ▪ KirchhoffMatrix ▪ WeightedAdjacencyMatrix ▪ ...

Exporting Graphs »

Export export graphs into several graph formats

"GraphML" ▪ "GXL" ▪ "Graphlet" ▪ "Pajek" ▪ "TGF" ▪ "DOT" ▪ "DIMACS" ▪ "Graph6" ▪ "Sparse6" ▪ "LEDA"

New to Mathematica? Find your learning path »
Have a question? Ask support »