Wolfram Research

Function Repository Resource:

VertexCoordinateList

Source Notebook

Return the vertex coordinates of a graph

Contributed by: Ed Pegg Jr

ResourceFunction["VertexCoordinateList"][g]

returns the vertex coordinates of graph g.

Examples

Basic Examples

Given a graph, VertexCoordinateList returns the vertex coordinates in the expected order:

In[1]:=
edges = {1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3, 1 \[UndirectedEdge] 7, 1 \[UndirectedEdge] 8, 2 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 4, 2 \[UndirectedEdge] 5, 3 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 5, 4 \[UndirectedEdge] 6, 5 \[UndirectedEdge] 6, 5 \[UndirectedEdge] 8, 6 \[UndirectedEdge] 7, 7 \[UndirectedEdge] 8};
g = Graph[edges, GraphLayout -> "TutteEmbedding", VertexLabels -> "Name"];
Grid[{{g, Graphics[
    MapIndexed[Text[#2[[1]], #1] &, ResourceFunction["VertexCoordinateList"][g]]]},
  {Graphics[MapIndexed[Text[#2[[1]], #1] &, GraphEmbedding[g]]], Graphics[
    MapIndexed[Text[#2[[1]], #1] &, GraphEmbedding[g][[VertexList[g]]]]]}}, Frame -> All]
Out[3]=

The vertex coordinate list can be used with the given edges:

In[4]:=
Graphics[Line[ResourceFunction["VertexCoordinateList"][g][[#]]] & /@ List @@@ edges]
Out[4]=

The raw form of the output:

In[5]:=
ResourceFunction["VertexCoordinateList"][g]
Out[5]=

Neat Examples

In[6]:=
edges = RandomSample[{1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3, 1 \[UndirectedEdge] 4, 1 \[UndirectedEdge] 5, 2 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 6, 3 \[UndirectedEdge] 7, 4 \[UndirectedEdge] 7, 4 \[UndirectedEdge] 8, 5 \[UndirectedEdge] 9, 5 \[UndirectedEdge] 10, 6 \[UndirectedEdge] 7, 6 \[UndirectedEdge] 8, 6 \[UndirectedEdge] 10, 8 \[UndirectedEdge] 9, 9 \[UndirectedEdge] 10}];
g = Graph[edges, GraphLayout -> "TutteEmbedding", VertexLabels -> "Name"];
Grid[{{g, Graphics[
    MapIndexed[Text[#2[[1]], #1] &, ResourceFunction["VertexCoordinateList"][g]]]},
  {Graphics[MapIndexed[Text[#2[[1]], #1] &, GraphEmbedding[g]]], Graphics[
    MapIndexed[Text[#2[[1]], #1] &, GraphEmbedding[g][[VertexList[g]]]]]}}, Frame -> All]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information