7

Bug introduced in 10.0 or earlier and fixed in 12.0


g = 
  Graph[{2 \[DirectedEdge] 3}, 
    VertexLabels -> "Name", EdgeLabels -> {2 \[DirectedEdge] 3 -> "hallo"}]

g has an edge pointing towards 3 from 2 labeled with "hallo"

g1 = VertexReplace[g, Thread[VertexList[g] -> ToString /@ VertexList[g]]];

g1 doesn't have that edge label because the edge labels 2 -> 3 -> "hallo" is still being identified using numerical $2$ and $3$.

Also I cannot save g1 as a .png file: if I right click, I get this message:

Set::write: Tag Inherited in Inherited[State] is Protected.

I am using Mathematica 11.0, My vertices are actually tuples like the following

g = 
  Graph[{{1,2} \[DirectedEdge] {2,3}}, 
    VertexLabels -> "Name", EdgeLabels -> {{1,2} \[DirectedEdge] {2,3} -> "hallo"}]

update with @m_goldberg's solution

In[15]:= Fold[
 SetProperty[{#1, #2}, VertexLabels -> ToString[#2]] &, g, 
 VertexList[g]]

During evaluation of In[15]:= SetProperty::pvobj: $Failed is not an object with properties.

Out[15]= SetProperty[{$Failed, {2, 3}}, VertexLabels -> "{2, 3}"]
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Neel Basu
  • 961
  • 6
  • 14

1 Answers1

4

It is better to use SetProperty and Fold for what you want to do.

g = 
  Graph[{2 \[DirectedEdge] 3},
    VertexLabels -> "Name",
    EdgeLabels -> {2 \[DirectedEdge] 3 -> Style[" hello ", Background -> White]}]

g

Fold[SetProperty[{#1, #2}, VertexLabels -> ToString[#2] <> "*"] &, g, VertexList[g]]

xg

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • Doesn't work if vertex identifiers are tuples, (question updated). However This is updating vertex label not vertex identifiers. – Neel Basu Nov 25 '16 at 08:26