4
$\begingroup$

Consider the following two graphs:

graph1 = Graph[{1, 2, 3}, {1 -> 3, 2 -> 3}, VertexLabels -> {3 -> 3, 2 -> 2, 1 -> 1}]

graph2 = Graph[{1, 2, 3}, {1 -> 3, 2 -> 3}, VertexLabels -> {3 -> 3, 2 -> 1, 1 -> 2}]

and the list containing both

graphlist = {graph1, graph2} 

The code:

testgraphs = 
 SetProperty[#, 
    VertexLabels -> {v_ :> Placed[{Style[v, Blue]}, {Above}]}] & /@ 
  graphlist

produces two V-shaped graphs, for which the labels (displayed in Blue) are the same for each vertex (across the graphs).

I expect these to be different as the VertexLabels for graph1 and graph2 are different.

Is there an issue with the code?

$\endgroup$
1
  • 1
    $\begingroup$ v_ :> Placed[{Style[v, Blue]}, {Above}] labels every node with its name (not with its VertexLabels in the input graph.) $\endgroup$
    – kglr
    Mar 22 at 7:42
5
$\begingroup$

Try

testgraphs = SetProperty[#,  VertexLabels -> {v_ :> 
    Placed[{Style[PropertyValue[{#, v}, VertexLabels], Blue]}, {Above}]}] & /@ 
   graphlist;

testgraphs

enter image description here

$\endgroup$
3
  • $\begingroup$ Very confusing: I tried both Style[PropertyValue[{#, v}, VertexLabels], Blue] and removing the assignment testgraphs = separately. Neither worked separately. The combination works. Is it because the language is so buggy? Or am I missing something regarding the constructs? $\endgroup$
    – Mike
    Mar 22 at 7:29
  • $\begingroup$ @Mike, can you post the code(s) that did not /did work? $\endgroup$
    – kglr
    Mar 22 at 7:43
  • $\begingroup$ I just checked and it actually works for assignments. Only fails for {Style[v, Blue]} $\endgroup$
    – Mike
    Mar 22 at 7:59

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.