10
$\begingroup$

If I have already created a graph using Graph. Later, I want to add to the graph some vertex and/or edge labels, how can I do that?

Thank you.

$\endgroup$
8
$\begingroup$

A random graph without any labeling:

g = RandomGraph[{11, 21}]

enter image description here

You can use SetProperty to add labeling P.S.

SetProperty[g, {EdgeLabels -> {3 \[UndirectedEdge] 4 -> "COOL"}, 
  VertexLabels -> {1 -> "STUFF"}}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ actually in version 8.0.0.0, it is not working SetProperty[g, {EdgeLabels -> {3 \[UndirectedEdge] 4 -> "COOL"}, VertexLabels -> {1 -> "STUFF"}}]. Looks like SetProperty can only set one property at a time. $\endgroup$ – Qiang Li Feb 21 '12 at 22:26

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.