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.

I'm trying to create a graph which has $\{a,b\}$ as labels:

g := Graph[{1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10, 
   1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2, 
   10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3, 
   9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7, 
   8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3, 
   7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2, 
   6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3, 
   5 \[UndirectedEdge] 4}]

Any help would be appreciated.

share|improve this question
    
How can you detect Petersen-Graph-ness? –  Loie Benedicte Aug 4 '13 at 18:56
add comment

3 Answers

Not sure what style you prefer, I'm showing you how to label both the vertices and the edges.

For clarity, let's define the edges into its own variable:

v = {1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10, 1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,  10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3, 9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7, 8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3, 7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3, 5 \[UndirectedEdge] 4};

Edge label:

edgeLabels = (# -> #) & /@ v;
g = Graph[v, EdgeLabels -> edgeLabels]

Vertex label:

vertexLabels = (# -> #) & /@ Range[10];
g = Graph[v, VertexLabels -> vertexLabels]
share|improve this answer
add comment

You can enter graph vertices and edges as strings and display using VertexLabels->"Name". For illustration purposes using the graph g provided:

graph=UndirectedEdge @@ CharacterRange["a", "j"][[#]] & /@ 
 List @@@ EdgeList[g]
Graph[graph,VertexShapeFunction->"Circle",VertexLabels->Placed["Name",Center],VertexStyle->White,VertexSize->0.5] 

yields:

enter image description here

share|improve this answer
add comment

Simple way to do this:

Graph[{1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10, 
1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2, 
10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3, 
9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7, 8 \[UndirectedEdge] 4,
7 \[UndirectedEdge] 3, 7 \[UndirectedEdge] 2, 
6 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3,
5 \[UndirectedEdge] 4}, 
 VertexLabels -> {1 -> "A", 2 -> "B", 3 -> "A", 4 -> "B", 5 -> "A", 
  6 -> "B", 7 -> "A", 8 -> "B", 9 -> "A", 10 -> "B"}]

Graph

share|improve this answer
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.