4
$\begingroup$

For example, if there is a graph

g = CompleteGraph[5, VertexLabels -> {1 -> "v1", 2 -> "v2", 3 -> "v3", 4 -> "v4", 5 -> "v5"}]

How can I later get the vertex labels of this graph? Something like:

RetrieveVertexLabels[g]

{{1,"v1"}, {2,"v2"}, {3,"v3"}, {4,"v4"}, {5,"v5"}}

I know similar functions exist for VertexList / EdgeList.

Thanks!

$\endgroup$
2
  • 1
    $\begingroup$ VertexLabels /. AbsoluteOptions[g, VertexLabels] might work. $\endgroup$ Commented Jun 29, 2015 at 1:55
  • $\begingroup$ Indeed, thanks!! $\endgroup$
    – smörkex
    Commented Jun 29, 2015 at 2:00

1 Answer 1

5
$\begingroup$
List @@@ PropertyValue[g, VertexLabels]

{{1, "v1"}, {2, "v2"}, {3, "v3"}, {4, "v4"}, {5, "v5"}}

or

List @@@ Options[g, VertexLabels][[1, 2]]
(* same output *)
$\endgroup$
1
  • $\begingroup$ This one is great, thanks! $\endgroup$
    – smörkex
    Commented Jun 29, 2015 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.