3
$\begingroup$

I am working with a graph with VertexLabels determined as follows:

 SetProperty[g, VertexLabels -> {v_ :> Placed[{Style[PropertyValue[{g, v}, VertexWeight], Black], Style[PropertyValue[{g, v}, VertexWeight], Red], Style[PropertyValue[{g, v}, VertexLabels], Blue]}, {Before, After, After} ]}]; 

The double use of After means both

Style[PropertyValue[{g, v}, VertexWeight], Red] 

and

Style[PropertyValue[{g, v}, VertexLabels], Blue] 

occur overlapping one another (i.e. in the same spot)

Is it possible to have some space between these? How can it be implemented?

ETA: I could use Above, but I definitely want the two values to occur after the node and spaced out so they are legible. I tried the After display to form a single pair (list of two elements), but could not get it to work.

$\endgroup$

1 Answer 1

3
$\begingroup$
g = CycleGraph[3, VertexWeight -> {100, 200, 300}, VertexLabels -> {v_:>{"A", "B", "C"}[[v]]}] 

enter image description here

You can use symbolic positions {After, Above} and {After, Below}:

SetProperty[g, VertexLabels -> {v_ :> Placed[{Style[PropertyValue[{g, v}, VertexWeight], Black], Style[PropertyValue[{g, v}, VertexWeight], Red], Style[PropertyValue[{g, v}, VertexLabels], Blue]}, {Before, {After, Above}, {After, Below}}]}] 

enter image description here

Alternatively, replace {Before, {After, Above}, {After, Below}} with {Before, {{1, 0}, {0, -1}}, {{1, 0}, {0, 1}}} to get the same picture.

The second approach is more flexible in that we can specify arbitrary number of labels and positions:

SetProperty[g, VertexLabels -> {v_ :> Placed[{Style[PropertyValue[{g, v}, VertexWeight], Black], Style[PropertyValue[{g, v}, VertexWeight], Red], ## & @@ (Style[PropertyValue[{g, v}, VertexLabels], #] & /@ {Blue, Green, Orange, Red, Purple})}, {Before, ## & @@ ({{2, 0}, {0, #}} & /@ Range[-2, 3, 1])}]}] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.