Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  bbgodfrey Mar 29 at 21:20
1  
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 –  penguin77 Mar 29 at 23:18

1 Answer 1

up vote 0 down vote accepted

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}]
share|improve this answer
    
Thank you very much, very useful. :-) –  AGEscovar Apr 2 at 1:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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