I have a list of (x, y, t), ( a pretty good analogy for the data is raindrops hitting a 2D plane over a period of time) and I'm trying to create a video on Mathematica so I can see visually how these points relate to each other.

Basically, the first frame should have no "raindrops" and the last frame should have the location of every raindrop that has fallen. I believe I can do this by creating a bunch of "snapshots" of the data at $t_1$, $t_1 + \Delta t$, $t_1 + 2 \Delta t$, and using an if loop through the (x, y, t) list to see which points would appear on each snapshot, then stringing a bunch of ListPlots together into a video, but this seems like a pretty inefficient way to do it.

Is there a simpler way to create a video given (x, y, t) birth sites in only a couple lines of code?

  • 1
    $\begingroup$ Can't you build up a dummy minimal example? You could save a Table parametrized by $t$ and then Export it, for example. $\endgroup$
    – anderstood
    Sep 12, 2017 at 18:29
  • $\begingroup$ sort the points on t if they aren't already ordered, then I see no need for an If conditional. Look up ListAnimate btw. $\endgroup$
    – george2079
    Sep 12, 2017 at 18:32
  • 1
    $\begingroup$ drops=Table[RandomReal[{0,20},3],{200}]; Export["movie.avi", Table[ListPlot[Map[Most, Select[drops, #[[3]]<t&]], PlotRange->{{0,20},{0,20}}], {t,1,20}]]; efficiency=1/(Number of seconds spent worrying about efficiency+Number of seconds spent writing it+Number of seconds spent running it) $\endgroup$
    – Bill
    Sep 12, 2017 at 19:01
  • $\begingroup$ @Bill The coefficient in front of "number of seconds spent running it once" can be very large :) $\endgroup$
    – anderstood
    Sep 12, 2017 at 19:12

2 Answers 2


You can use Select together with Animate and ListPlot to achieve what you want:

(* some random data *)
data = RandomReal[{0, 1}, {100, 3}];

  Select[data, Last@# < t &][[All, {1, 2}]],
  PlotRange -> {{0, 1}, {0, 1}},
  Frame -> True
 {t, 0, 1}

resulting animation


pre sort the data into frames then use ListAnimate :

data = RandomReal[{0, 1}, {1000, 3}];

nframes = 50;
sorted = GatherBy[data, Round[#[[3]], 1/(nframes - 1)] &][[All, 
   All, {1, 2}]];
 ListPlot[#, PlotRange -> {{0, 1}, {0, 1}}] & /@ 
  FoldList[Join, {}, sorted]]

if the data is already in time order you could also use SplitBy


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.