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.

Consider the list {1,2,3,4,3,4,2,1}. I want to label these points on circle the way they appear on list(clockwise, counter clock wise doesn't matter). After that I want to connect same points by straight lines. I am not sure how to do this. Any comment appreciated.

I tried:

a = {1, 2, 3, 4, 3, 4, 2, 1}; 
b = DeleteDuplicates[a]; 
c1 = Flatten[Position[a, #, 1][[1]] & /@ b];
c2 = Flatten[Position[a, #, 1][[2]] & /@ b];
pts = Table[{2 Cos[t], 2 Sin[t]}, {t, 0, 2 Pi, 2 Pi/8}]; 
f[x_] := Graphics[Line[{pts[[c1[[x]]]], pts[[c2[[x]]]]}]];

But this give lines separate from each other. Also How do you add circle to that? After @cormullion answer I removed my function. Now I have what I want but without labels.

a = {1, 2, 3, 4, 5, 1, 2, 3, 5, 4};
b = DeleteDuplicates[a];
c2 = Flatten[Position[a, #, 1][[2]] & /@ b];
c1 = Flatten[Position[a, #, 1][[1]] & /@ b];
r = 2;(*radius*)
pts = Table[{r*Cos[t], r*Sin[t]}, {t, 0, 2 Pi, 2 Pi/Length[a]}];
Graphics[{Circle[{0, 0}, r], 
  Line[{pts[[c1[[#]]]], pts[[c2[[#]]]]}] & /@ Range[Length[b]]} ]

enter image description here

share|improve this question
    
@rm-rf The points are put on circle in same distance from each other. Since we have 8 values I think we can use 2pi/8. Then I want to connect 1-1, 2-2,likewise. think correct word is label (not mark). –  Vajira Oct 31 '13 at 18:45
    
Would you like to rename your question "how do I label this diagram?" :) –  cormullion Oct 31 '13 at 20:07
    
@cormullion Yes. That would be great.:) –  Vajira Oct 31 '13 at 20:11
add comment

2 Answers

up vote 9 down vote accepted

A pretty easy solution is to use Graph because there you can

  • create edges
  • position the vertices on a circle
  • label all vertices
  • put a circle on it

A somewhat condensed form of this idea is the following

drawMe[l_List] :=
 With[{ed = Range[Length[l]], dphi = 2 Pi/(Length[l])},
  Graph[ed, (UndirectedEdge @@@ 
        Subsets[Flatten[#], {2}]) & /@ (Position[l, #] & /@ 
       Union[l]) // Flatten, 
   VertexLabels -> (Rule @@@ Transpose[{ed, l}]),
   VertexCoordinates -> 
    Table[{Cos[phi], Sin[phi]}, {phi, 0, 2 Pi - dphi, dphi}], 
   Epilog -> {Circle[]}, ImagePadding -> 15]]

drawMe[{1, 2, 3, 4, 5, 1, 2, 3, 5, 4}]

Mathematica graphics

Btw, you can create nice things with this

drawMe@Table[Mod[i, 8], {i, 2^6}]

Mathematica graphics

share|improve this answer
add comment

This is how I would do it:

coords[list_] := 
  With[{offset = 2 Pi/Length[list]}, Array[{Cos[# offset], Sin[# offset]} &, Length[list]]]
lines[list_] := Line[coords[list][[#]] & /@ Partition[Ordering[list], 2]]
labels[labels_, scaling_] := MapThread[Text, {labels, scaling coords[labels]}]

b = {1, 2, 3, 4, 5, 1, 2, 3, 5, 4};
Graphics[{
  Circle[],
  lines[b],
  labels[b, 1.1]
  }]

gfx

It assumes there are two of each label. It would have to be adjusted to work for other cases. I think the labeling function will work for your case as well. What it does is take the coordinates of the vertices and multiply them by some constant, to put them further away from the middle.

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.