3
$\begingroup$

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

$\endgroup$
8
$\begingroup$
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

$\endgroup$
4
$\begingroup$
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

$\endgroup$
1
$\begingroup$
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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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