0
$\begingroup$

I'm having trouble running some animations, I would appreciate some help.

I want to use the ListAnimate to show the results of a Monte Carlo simulation, that I have stored in a data file. I'm trying to show two simultaneous animations in a single plot. I have managed to do this by using Manipulate and then running the simulation automatically. However, I still feel that that this could be done using ListAnimate. Any ideas or suggestions as to how this may be possible?

As an example, the specific code I use in Manipulate is:

Manipulate[
 Show[ListLinePlot[data1[[n]], PlotRange -> {0, 10}, Joined -> True], 
  ListLinePlot[data2[[n]], PlotRange -> {0, 10}, Joined -> True]], {n,
   1, 2, 1}]

In this case, the lists have the same number of objects, but they may contain different number of objects, in which case I could just use two variables instead of one, however, running them simultaneously proves to be a problem.

That way I just use the play button on the control options and it runs, that is, it plots both graphs on the same plot and the animation runs. This is fine, however I find that a ListAnimate function would be more suitable for the number of points I have to plot. How could I do this?

$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented Mar 29, 2015 at 21:20
  • 1
    $\begingroup$ Do you mean: Manipulate[ Show[ListLinePlot[data1[[n]], PlotRange -> {0, 10}, Joined -> True], ListLinePlot[data2[[n]], PlotRange -> {0, 10}, Joined -> True]], {n, 1, 2, 1}] ? please review your example code to be syntactically correct, thanks $\endgroup$
    – penguin77
    Commented Mar 29, 2015 at 23:18

1 Answer 1

1
$\begingroup$

Here the code using ListAnimate

data1 = {{{0, 2}, {1, 4}}, {{0, 2}, {1, 8}}};
data2 = {{{0, 3}, {3, 4}}, {{1, 5}}};
    Show /@ Transpose @  (Table[
       ListLinePlot[#[[n]], PlotRange -> {0, 10}, Joined -> True], {n,
         1, 2, 1}] & /@ {data1, data2}) // ListAnimate

ListAnimate animates a sequence of elements in a list by considering them as frames. Therefore all ListLinePlot results need to be generated in a list for being animated. I would prefer your initial solution using Manipulate, however this is subjective. Please correct your syntax of code in your question. It should be like this:

Manipulate[
 Show[ListLinePlot[data1[[n]], PlotRange -> {0, 10}, Joined -> True], 
  ListLinePlot[data2[[n]], PlotRange -> {0, 10}, Joined -> True]], {n,
   1, 2, 1}]
$\endgroup$
1
  • $\begingroup$ Thank you very much, very useful. :-) $\endgroup$
    – user27381
    Commented Apr 2, 2015 at 1:21

Your Answer

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