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 would like to write a code in Mathematica such that it shows the direction with numbers on points. I wrote this code which does not do this. I want just to complete this code with two options I told. Any Idea. thanks.

ListPolarPlot[{Table[{2^n, 1}, {n, 1, 6}]}, Joined -> True,PlotStyle -> {Blue, Red, Green, Yellow, Gray}, Mesh -> All, MeshStyle -> Red]

enter image description here

share|improve this question

3 Answers 3

up vote 8 down vote accepted
data = Reverse@Table[{2^n, 1}, {n, 1, 6}];
Graph[Table[DirectedEdge[i, i + 1], {i, Length@data - 1}], 
  VertexLabels -> "Name", VertexCoordinates -> ({#2 Cos[#1], #2 Sin[#1]} & @@@ data), 
  Axes -> True, ImageSize -> 300]

enter image description here

share|improve this answer
foo := Module[{r = Transpose@Through[{Cos, Sin}[2^Range[#]]], p},
              p = Partition[r, 2, 1]; 
              Graphics[{Opacity[.5], Red, Disk[#, .05] & /@ r, Opacity[1],
                        Black, Text @@@ MapIndexed[{First@#2, #} &, r],
                        Arrow[#, .05] & /@ p},
                        PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}]] &

foo@8

enter image description here

ListAnimate[Table[foo[i], {i, 2, 50}], AnimationDirection -> ForwardBackward]

enter image description here

Edit: post-processing ListPolarPlot output as in eldo's answer:

 n = 14; 
 Block[{i = 1, xx = {}}, 
  ListPolarPlot[Partition[Thread@{2^Range[n], 1}, 2, 1], 
               Joined -> True, BaseStyle -> Arrowheads[.05], 
               PlotStyle -> (Hue /@ (Range[n]/n))] /. 
    Line[x_] :> {Disk[x[[1]], .07], 
                 Text[Style[i++, 14, Black], x[[1]]], Arrow[xx = x, .05]} /. 
    Arrow[xx, .05] :> {GrayLevel[.7], Disk[xx[[2]], .07], 
                       Text[Style[i++, 14, Black], xx[[2]]], Arrow[xx, .05]}]

enter image description here

share|improve this answer
    
+1 for fancyness :) –  eldo Aug 12 at 19:41
    
Thank you @eldo.. –  kguler Aug 12 at 19:50
PolarGraph[n_Integer] :=
 Module[{lp = ListPolarPlot @ Table[{2^x, 1}, {x, 1, n}], p, a, t},
  p = Reverse @ Take [Cases[lp, {_Real, _Real}, -1], n];
  a = Arrow /@ Partition[p, 2, 1];
  t = Text @@@ Transpose[{Range @ Length @ p, p}] /.
    Text[u_, v_] :> Text[Style[u, Red, 16], v + 0.1];
  Graphics[{a, t}, Axes -> True]]

PolarGraph[7]

enter image description here

share|improve this answer

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.