谷歌没有给我答案的原因是我不知道在这种情况下列表元素的正确名称(*)。这里我有一些输入数据:
edges = ReadList["some\\external\\data\\source\\1"]
(* edges = { 0 -> 1, 1 -> 2, 2 -> 3 } *)
labels = ReadList["some\\external\\data\\source\\2"]
(* labels = { 0 -> A, 1 -> B, 2 -> A, 3 -> B } *)
我想从标签创建一个新列表样式,并将 A 替换为红色和 B 到绿色所以我可以得到:
styles = { 0 -> Red, 1 -> Green, 2 -> Red, 3 -> Green }
我用它来绘制图表:
Graph [ edges, VertexLabels -> labels, VertexStyle -> styles ]
(*)尝试了对列表,转换列表,边缘列表,但发现RightArrow运算符具有一般含义......
答案 0 :(得分:3)
我想你想要这个:
edges = {0 -> 1, 1 -> 2, 2 -> 3}
labels = {0 -> A, 1 -> B, 2 -> A, 3 -> B}
styles = labels /. {A -> Red, B -> Green}
Graph[edges, VertexLabels -> labels, VertexStyle -> styles]
答案 1 :(得分:0)
如何从“数据库”开始:
edges[0] = 1; edges[1] = 2; edges[2] = 3;
labels[0] = "A"; labels[1] = "B"; labels[2] = "A"; labels[3] = "B";
然后是一些替换规则:
s["A"] = "Red"; s["B"] = "Green";
可让您定义新的labels
功能:
styles[e_] := s[labels[e]]
给出了
In[9]:= Table[styles[i], {i, 0, 3}]
Out[9]= {"Red", "Green", "Red", "Green"}
等...