GraphCoordinates[g,options]
calculates a visually appealing 2D layout of the vertices of the graph g and returns the coordinates of the vertices.
GraphCoordinates
GraphCoordinates[g,options]
calculates a visually appealing 2D layout of the vertices of the graph g and returns the coordinates of the vertices.
Details and Options
- GraphCoordinates functionality is now available in the built-in Wolfram Language function GraphEmbedding.
- To use GraphCoordinates, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
- GraphCoordinates returns the coordinates of the vertices as computed using a graph-drawing algorithm. This is useful when you need to draw a graph repeatedly using the same layout but different styles.
- GraphCoordinates accepts the same options as GraphPlot.
Examples
open all close allBasic Examples (2)
Needs["GraphUtilities`"]Needs["GraphUtilities`"]g = {1 -> 2, 2 -> 3, 3 -> 1, 1 -> 4, 2 -> 5, 5 -> 6, 6 -> 7};GraphPlot[g]This gives the coordinates of the vertices in the previous drawing:
GraphCoordinates[g]GraphCoordinates has been superseded by GraphEmbedding:
g = Graph[{1 -> 2, 2 -> 3, 3 -> 1, 1 -> 4, 2 -> 5, 5 -> 6, 6 -> 7}]GraphEmbedding[g]Scope (1)
Needs["GraphUtilities`"]g = {10 -> 11, 11 -> 12, 12 -> 7, 1 -> 7, 2 -> 8, 3 -> 9, 4 -> 10, 5 -> 11, 6 -> 12, 7 -> 13, 9 -> 13, 11 -> 13, 1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 1, 7 -> 8, 8 -> 9, 9 -> 10};GraphPlot[g]This gives the coordinates of the vertices in the previous drawing:
coords = GraphCoordinates[g]This plots the graph with two different styles, using the layout already calculated:
Row[{GraphPlot[g, VertexLabeling -> True, VertexCoordinateRules -> coords], GraphPlot[g, DirectedEdges -> True, VertexCoordinateRules -> coords]}]The relationship between vertices and coordinates is given by the following:
Thread[Rule[VertexList[g], coords]]Properties & Relations (1)
This shows a drawing of a small graph, and the coordinates associated with the drawing:
Needs["GraphUtilities`"]g = {5 -> 4, 6 -> 2, 6 -> 3, 6 -> 5, 7 -> 1, 7 -> 3, 7 -> 4, 7 -> 6};GraphPlot[g, VertexLabeling -> True]coord = GraphCoordinates[g]This shows the relationship between vertex labels and their coordinates:
Thread[VertexList[g] -> coord]The coordinates can be reused to create the drawing without recomputing:
GraphPlot[g, VertexLabeling -> True, VertexCoordinateRules -> coord]Possible Issues (1)
This shows the LayeredGraphPlot of a directed graph:
Needs["GraphUtilities`"]g = {1 -> 2, 2 -> 3, 1 -> 3, 1 -> 3, 3 -> 3};LayeredGraphPlot[g, VertexLabeling -> True]GraphCoordinates only returns the position of the vertices:
coord = GraphCoordinates[g, Method -> "LayeredDigraphDrawing"]The curved edges between vertices 1 and 3 are not reproduced:
LayeredGraphPlot[g, VertexCoordinateRules -> coord, VertexLabeling -> True]Interactive Examples (1)
This shows how to travel from vertex 1 to 7 through the shortest path:
Needs["GraphUtilities`"]DynamicModule[{g, coord, path, edges}, g = {1 -> 2, 1 -> 3, 1 -> 17, 2 -> 5, 2 -> 15, 3 -> 4, 3 -> 19, 4 -> 5, 4 -> 20, 5 -> 13, 6 -> 7, 6 -> 8, 6 -> 18, 7 -> 10, 7 -> 11, 8 -> 9, 8 -> 16, 9 -> 10, 9 -> 14, 10 -> 12, 11 -> 13, 11 -> 20, 12 -> 13, 12 -> 15, 14 -> 15, 14 -> 17, 16 -> 17, 16 -> 19, 18 -> 19, 18 -> 20};
coord = GraphCoordinates[g];
path = GraphPath[Flatten[{g, Map[Reverse, g]}], 1, 7];
edges = Transpose[{Drop[path, -1], Drop[path, 1]}];
Manipulate[pe = Take[edges, length];
GraphPlot[g, VertexLabeling -> True, VertexCoordinateRules -> coord, EdgeRenderingFunction -> ({If[MemberQ[pe, #2] || MemberQ[pe, Reverse[#2]], Sequence@@{Thickness[0.01], Red}, Black], Line[#1]}&), ImageSize -> 300], {length, 1, Length[edges], 1}]]See Also
Tech Notes
Related Guides
-
▪
- Graph Utilities Package ▪
- Graphs & Networks ▪
- Graph Visualization ▪
- Computation on Graphs ▪
- Graph Construction & Representation ▪
- Graphs and Matrices ▪
- Graph Properties & Measurements ▪
- Graph Operations and Modifications ▪
- Statistical Analysis ▪
- Social Network Analysis ▪
- Graph Properties ▪
- Mathematical Data Formats ▪
- Discrete Mathematics
Text
Wolfram Research (2007), GraphCoordinates, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/GraphCoordinates.html.
CMS
Wolfram Language. 2007. "GraphCoordinates." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/GraphCoordinates.html.
APA
Wolfram Language. (2007). GraphCoordinates. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/GraphCoordinates.html
BibTeX
@misc{reference.wolfram_2026_graphcoordinates, author="Wolfram Research", title="{GraphCoordinates}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GraphUtilities/ref/GraphCoordinates.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_graphcoordinates, organization={Wolfram Research}, title={GraphCoordinates}, year={2007}, url={https://reference.wolfram.com/language/GraphUtilities/ref/GraphCoordinates.html}, note=[Accessed: 13-June-2026]}