Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In the examples I have seen, graph vertices in Mathematica are usually explicit small integers. However, Wolfram documentation says that vertices can be any arbitrary expression (eg., george, x^2, London, 5).

Nevertheless, it seems that vertices are always referred to by number, that is, by the position of the vertex expression in VertexList[gr]. This can be confusing. For example, if I build a graph like this, using nonconsecutive vertex numbers,

Graph[1<->2, 2<->10, 10<->3, 3<->4]

then I still have to refer to the vertices as if I had made each vertex number equal to its creation order, as if I had built the graph with strictly consecutive vertex numbers:

Graph[1<->2, 2<-3 ,3<->4, 4<->1] 

Am I understanding this correctly?

share|improve this question
add comment

1 Answer 1

No, you can refer to the vertices in any order and it will pair it accordingly. Compare the following:

g1 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, VertexLabels -> "Name"]

enter image description here

g2 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, 
    VertexLabels -> {1 -> "a", 10 -> "b", 2 -> "c", 4 -> "d", 3 -> "e"}]

enter image description here

Note that in the second case, I named the vertices in a different order than what was entered and did not use sequential numbers.

share|improve this answer
    
But if I write: codeg1 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, VertexLabels -> "Name"]; GraphPlot[g1,VertexLabeling->True] then the result uses only the digits 1 through 8. That is, at the very least, confusing, don't you think? –  Ralph Dratman Jul 12 '12 at 17:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.