2
$\begingroup$

I want to make a animation based on the dataset like

data = Flatten[Table[{x, y, x^2 - y^2}, {x, -3, 3}, {y, -3, 3}], 1];

I show this data using a ListPlot3D.

p2[θ_] := RotationTransform[θ, {0, 0, 1}]

When I use Table to generate the different images, it works fine.

test11 = Table[
  ListPlot3D[p2[a][data] /. {x_, y_, z_} -> {x, y, z*a}, Mesh -> 5, 
   MeshStyle -> White, Axes -> {False, False, True}, 
   PlotRange -> {{-4, 4}, {-4, 4}, {-10, 10}}], {a, -1, 1, 0.1}]

Export["anigraf2.GIF", test11, "DisplayDurations" -> 1]

When I use 'Animate' to create the same output, Mathematica stops responding en I have to restart the software.

Animate[ListPlot3D[p2[a][data] /. {x_, y_, z_} -> {x, y, z*a}, 
  Mesh -> 5, MeshStyle -> White, Axes -> False, 
  PlotRange -> {{-4, 4}, {-4, 4}, {-10, 10}}], {a, -1, 1, 0.1}, 
 AnimationDirection -> ForwardBackward, AnimationRunning -> True, 
 SaveDefinitions -> True]

Is there somebody who has suggestion for this issue?

$\endgroup$
  • 6
    $\begingroup$ For anything but the simplest of graphics objects, always avoid Animate and use ListAnimate instead, since it generates the frames beforehand. I've had Animate crash my entire system before, to where I needed to just restart my computer. Here, ListAnimate[test11, AnimationDirection -> ForwardBackward, AnimationRunning -> True, SaveDefinitions -> True] works perfectly. $\endgroup$ – Jason B. Apr 25 '16 at 15:07
  • $\begingroup$ @JasonB, pls make it an answer and elaborate on the issue, so we can succesfully close this Q&A. $\endgroup$ – user9660 Apr 26 '16 at 8:09
  • 1
    $\begingroup$ @Louis - done! (comments must be at least 15 characters in length) $\endgroup$ – Jason B. Apr 26 '16 at 8:52
3
$\begingroup$

For anything but the simplest of graphics objects, always avoid Animate and use ListAnimate instead.

The difference is that ListAnimate works on a pre-defined list of images to create an animation. All the rendering is done beforehand. With Animate, it attempts to do the rendering on the fly, when you are moving the slider.

So this will make the animation you are looking for,

data = Flatten[Table[{x, y, x^2 - y^2}, {x, -3, 3}, {y, -3, 3}], 1];
p2[θ_] := RotationTransform[θ, {0, 0, 1}];
imglist = Table[
   ListPlot3D[p2[a][data] /. {x_, y_, z_} -> {x, y, z*a}, Mesh -> 5, 
    MeshStyle -> White, Axes -> {False, False, True}, 
    PlotRange -> {{-4, 4}, {-4, 4}, {-10, 10}}]
   , {a, -1, 1, 0.1}];
ListAnimate[
 imglist,
 AnimationDirection -> ForwardBackward, AnimationRunning -> True, 
 SaveDefinitions -> True]

Another option is to use Manipulate instead of Animate. Manipulate will render the 3D graphics using fewer points when you are moving the slider, giving you the changes quickly when it can at the expense of quality, and then generating the higher quality images when the slider stops moving. (Correct me if I am wrong here) I do not think that Animate does this.

So this runs relatively quickly on my machine,

Manipulate[
 ListPlot3D[p2[a][data] /. {x_, y_, z_} -> {x, y, z*a}, Mesh -> 5, 
  MeshStyle -> White, Axes -> {False, False, True}, 
  PlotRange -> {{-4, 4}, {-4, 4}, {-10, 10}}]
 , {a, -1, 1, 0.05}]

enter image description here

$\endgroup$
  • $\begingroup$ Well done & cool attitude. $\endgroup$ – user9660 Apr 26 '16 at 13:03

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.