# Displaying vertex-labels and weights at vertex. Unexpected error (UPDATE AS BELOW)

The problem I flagged still occurs after replacing Vertexweights by VertexWeight.

The weights are displayed on the graph by \$Failed for the following code, but work fine for the code produced after (the only difference is that I used

temp = SetProperty


rather than

SetProperty


I don't see why this should be the case (I flagged a part of the code that showed up highlighted in blue at the end of this post).

Code which fails

temp = Graph[{x2 \[DirectedEdge] x1, x2 \[DirectedEdge] x4,
x5 \[DirectedEdge] x1, x5 \[DirectedEdge] x4,
x3 \[DirectedEdge] x2}]
SetProperty[temp,
VertexCoordinates ->
ReflectionTransform[{0, -1}]@GraphEmbedding[temp]]
SetProperty[temp, VertexWeight -> {1, 2, 3, 4, 5}]
SetProperty[temp, {VertexLabels -> {v_ :>
Placed[{"Name",
AnnotationValue[{temp, v}, VertexWeight]}, {Above, Below}]},


Code which works

temp = Graph[{x2 \[DirectedEdge] x1, x2 \[DirectedEdge] x4,
x5 \[DirectedEdge] x1, x5 \[DirectedEdge] x4,
x3 \[DirectedEdge] x2}]
temp = SetProperty[temp,
VertexCoordinates ->
ReflectionTransform[{0, -1}]@GraphEmbedding[temp]]
temp = SetProperty[temp, VertexWeight -> {1, 2, 3, 4, 5}]
temp = SetProperty[
temp, {VertexLabels -> {v_ :>
Placed[{"Name",
AnnotationValue[{temp, v}, VertexWeight]}, {Above, Below}]},


The only part that is highlighted in blue when I write the code is the use of x1 (and the others: x2 x3 x4 x5) in the first line of the code

Graph[{x2 \[DirectedEdge] x1, x2 \[DirectedEdge] x4,
x5 \[DirectedEdge] x1, x5 \[DirectedEdge] x4,
x3 \[DirectedEdge] x2}]

• replace VertexWeights with VertexWeight? – kglr Feb 26 at 9:05
• That worked. Oddly, VertexWeights did not produce an error. – Mike Feb 26 at 9:10
• SetProperty (and Annotate) does not produce errors because it is supposed to work to add custom properties (which may have arbitrary names). So the only clue that VertexWeights may be problematic is the blue syntax highlighting. – kglr Feb 26 at 9:23
• SetProperty "produce(s) an object with a modified property value." It does not do modification in place. So you need to use temp = SetProperty[temp,...] (as you in the last code block) to make the properties stick to temp. – kglr Feb 26 at 10:41
• Mike, posted the comment as answer. – kglr Feb 26 at 11:17

That is, SetProperty[obj,...] does not modify properties in place. We need to do obj = SetProperty[obj, ...] to modify the properties of obj.

Illustration using a simple example:

g0 = Graph[{1 -> 2, 2 -> 3}];
PropertyValue[g0, EdgeStyle]

Automatic

SetProperty[g0, EdgeStyle -> {(1 -> 2) -> Red, (2 -> 3) -> Green}]


PropertyValue[g0, EdgeStyle]

Automatic

g0 = SetProperty[g0, EdgeStyle -> {(1 -> 2) -> Red, (2 -> 3) -> Green}];

PropertyValue[g0, EdgeStyle]