3
$\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$
  • 1
    $\begingroup$ VertexLabels /. AbsoluteOptions[g, VertexLabels] might work. $\endgroup$ – J. M. will be back soon Jun 29 '15 at 1:55
  • $\begingroup$ Indeed, thanks!! $\endgroup$ – smörkex Jun 29 '15 at 2:00
3
$\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$
  • $\begingroup$ This one is great, thanks! $\endgroup$ – smörkex Jun 29 '15 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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