7
$\begingroup$

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}"]
$\endgroup$
  • $\begingroup$ Draw a graph to show what you want done. $\endgroup$ – Jose Enrique Calderon Nov 24 '16 at 20:38
  • $\begingroup$ The Set::write: message is a new but harmless bug in version 11. I have already reported it, but it won't hurt if you report it too. $\endgroup$ – Szabolcs Nov 25 '16 at 8:05
  • 1
    $\begingroup$ This message is blocking me from saving the graph as image. $\endgroup$ – Neel Basu Nov 25 '16 at 8:26
4
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Doesn't work if vertex identifiers are tuples, (question updated). However This is updating vertex label not vertex identifiers. $\endgroup$ – Neel Basu Nov 25 '16 at 8: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.