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?
Answer
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}]
Comments
Post a Comment