I am making a Mathematica animation, and exporting it to create a GIF file. However, I cannot seem to control the animation rate (speed) and the animation direction, using the "AnimationRate" and "AnimationDirection" options under the Export command.

p1 = Table[ Plot[k*x^2, {x, -2, 2}, PlotRange -> {-8, 8}], {k, -2, 2, 0.1}];

speed1 = Export["speed1.GIF", p1, "AnimationRate" -> 1, 

"AnimationRepetitions" -> Infinity, "AnimationDirection" -> ForwardBackward]

"speed1" is the output GIF file. However, regardless of what parameter you put for "AnimationRate", the GIF file always runs in a fixed speed. The same is true for the "AnimationDirection" option. Is there any way to resolve this? Any help would be greatly appreciated!

Thank you in advance! Tim


2 Answers 2


I use this method which seems to work well. After you create the table, Export is used with the option DisplayDurations.

You can also actually have the display duration a table of same length as the number of frames in the original table.

This way, you can also make different phases of the animation go faster or slower. I've done this on animations where I wanted it to slow down when something interesting happens, but speed up when nothing much is happening.

Here is an example. I had to make this small, since there is a limit of 2 MB here to put an image. Notice how it starts fast, then half way it slows down. it runs for 18 seconds. So the slow down starts at 9 seconds.

The code to generate this animation is

Export["anim_axis.gif", r, "DisplayDurations" -> 
  Table[If[n < Length[r]/2, .05, 0.2], {n, 1, Length[r]}]]

The If in the table is used to tell it to make rate 0.05 for the first half of the frames, and rate of 0.2 for the rest. So it goes faster first, then slows down.

enter image description here

If you do not want this fine control, and want same rate for al the frames, then just use

Export["anim_axis.gif", r, 
 "DisplayDurations" -> Table[0.05, {n, 1, Length[r]}]]

In the above, r is the actual table that contains the plots. Similar to your p1 variable. The code to generate this is not shown since not needed. But I can post it as well.

  • $\begingroup$ Thanks, Nasser! Your detailed explanation was very valuable. Especially, how to set up variable speeds for different frames was excellent. Just want to let you know that I appreciate your effort. Have a great day! $\endgroup$
    – user6009
    Oct 5, 2021 at 0:07
p1 = Animate[
  Plot[k*x^2, {x, -2, 2}, PlotRange -> {-8, 8}], {k, -2, 2, 0.1}, 
  AnimationDirection -> ForwardBackward]
Export["speed1.gif", p1, "ControlAppearance" -> None, 
 "AnimationRepetitions" -> Infinity, "AnimationRate" -> Automatic, 
 "DisplayDurations" -> 1/20]

enter image description here

  • $\begingroup$ Thank you so much for your detailed explanation! It was really appreciated. I have learnt from this, and thanks a whole lot! $\endgroup$
    – user6009
    Oct 3, 2021 at 4:23

Your Answer

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

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