1
$\begingroup$

I would like to animate a simple clip where the points appear at a plot

LIN = {};
Animate[Poin1 = RandomVariate[UniformDistribution[{{0, 1}, {0, 1}}]]; 
 LIN = Append[LIN, {Poin1}];
 TableForm[{{n}, ListPlot[LIN, ImageSize -> 500, PlotStyle -> Red] }], {n, 1, 5, 
  1}, AnimationRepetitions -> 1, AnimationRate -> .5 , 
 DisplayAllSteps -> True]

The code should result in the plot with increasing number of points, from 1 to 5. At the end, the plot should have 5 static points. But in fact, the points are being added in a continuous manner.

enter image description here

When I stop the animation at t=2, the points continue to appear. This looks like the animation works in a non-stop mode

$\endgroup$

2 Answers 2

0
$\begingroup$
Clear["Global`*"]

LIN = RandomVariate[UniformDistribution[{{0, 1}, {0, 1}}], 5];

Animate[
 ListPlot[LIN[[;; n]],
  PlotRange -> {{0, 1}, {0, 1}},
  PlotRangePadding -> Scaled[.05],
  ImageSize -> Medium,
  PlotStyle -> Red],
 {n, 1, 5, 1},
 AnimationRepetitions -> 1,
 AnimationRate -> .5,
 DisplayAllSteps -> True]

enter image description here

$\endgroup$
0
$\begingroup$

The points are adding up because you do nowheer reset LIN to an empty list.

Clear["Global`*"]
LIN = {};

fun = Function[{m}, If[m == 1, LIN = {}];
  AppendTo[LIN, RandomVariate[UniformDistribution[{{0, 1}, {0, 1}}]]]]

Animate[
  ListPlot[fun[n], ImageSize -> 500, PlotStyle -> Red]
 , {n, 1, 5, 1}, AnimationRepetitions -> 1, AnimationRate -> .5]

You will see that the animation does not exactly stop after 1 iteraion. It makes some additional steps. Why that is, I do not know.

$\endgroup$
2
  • $\begingroup$ Thank you, Daniel, this woks, when the points list is generated in advance. But there exists a side effect, at least, for me: n varies from 1 to 5 as needed, then returns to 1, 2, and again returns to 5. In brief, I see steps: 1,2,3,4,5,1,2,5 :(( $\endgroup$
    – Konstantin
    Commented Feb 11, 2022 at 17:08
  • $\begingroup$ I saw this too, but I do not know the reason. $\endgroup$ Commented Feb 11, 2022 at 17:25

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.