3
$\begingroup$

I am new to Mathematica, and I am trying to plot a sequence of 2D points so that the resulting video shows 1, then 2, then 3, ... points on the screen. Here is a simple minded version of what I am trying to do. It plots the first 3 points of the 20 points of an ellipse:

tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 \[Pi], 2 \[Pi]/20}]; 
pointTable = Table[Point[tab[[i]]], {i, 1, 20}]; 
Row[
 Show[Graphics[pointTable[[1]], PlotRange -> {{-5, 5}, {-3, 3}}, 
   Axes -> True, Ticks -> None]], 
 Show[Graphics[pointTable[[1 ;; 2]], PlotRange -> {{-5, 5}, {-3, 3}}, 
   Axes -> True, Ticks -> None]], 
 Show[Graphics[pointTable[[1 ;; 3]], PlotRange -> {{-5, 5}, {-3, 3}}, 
   Axes -> True, Ticks -> None]]
]

I haven't been able to use Do, or While or any other "loop" to generate an arbitrary number of points. I'll be most grateful for any help.

$\endgroup$
2
  • 1
    $\begingroup$ Welcome to the Mathematica Stack Exchange. Please explore the ListAnimate function as well. $\endgroup$
    – Syed
    Jan 7, 2023 at 5:58
  • $\begingroup$ Thank you Syed. Your suggestion was extremely useful. $\endgroup$ Jan 8, 2023 at 19:18

2 Answers 2

6
$\begingroup$

I am trying to plot a sequence of 2D points so that the resulting video shows 1, then 2, then 3, ... points on the screen

enter image description here

ClearAll["Global`*"]
tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 π, 2 π/20}];
plot[lis_List] := 
  ListPlot[lis, PlotRange -> {{-4.5, 4.5}, {-4.5, 4.5}}, 
   PlotStyle -> Red, GridLines -> Automatic, 
   GridLinesStyle -> LightGray];
Animate[plot[tab[[1 ;; n]]], {n, 1, Length[tab], 1}]

To display the point number also

enter image description here

tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 \[Pi], 2 \[Pi]/20}];
plot[lis_List, n_?NumericQ] := Grid[{{Row[{" point ", n}]},
    {ListPlot[lis, PlotRange -> {{-4.5, 4.5}, {-4.5, 4.5}}, 
      PlotStyle -> Red, GridLines -> Automatic, 
      GridLinesStyle -> LightGray, ImageSize -> 400]
     }}];
Animate[plot[tab[[1 ;; n]], n], {n, 1, Length[tab], 1}]
$\endgroup$
4
$\begingroup$

Welcome to mathematica.stackexchange.com

tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 \[Pi], 2 \[Pi]/20}];
pointTable = Table[Point[tab[[i]]], {i, 1, 20}];
Show[Graphics[pointTable[[1 ;; #]], PlotRange -> {{-5, 5}, {-3, 3}}, 
     Axes -> True, Ticks -> None]] & /@ Range[20] // Row

enter image description here

There may be a version with less code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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