3
$\begingroup$

When I make an animation of Plot3D using ListAnimate it looks decent. But when I export the same frames with Export, the z-axis tick labels jump back and forth. Here's a minimal example:

f = Table[
  Plot3D[(1 + Sin[2 \[Pi] t]) E^(-(x - Sin[2 \[Pi] t])^2 - (y - Cos[2 \[Pi] t])^2),
    {x, -2, 2}, {y, -2, 2}, PlotLabel -> t, PlotRange -> All, ViewPoint -> {-2, -2, 1}]
, {t, 0, 0.95, 0.05}];

ListAnimate[f]
(* looks OK *)

Export["f.gif", f, "AnimationRepetitions" -> \[Infinity]]
(* looks bad *)

enter image description here

Any idea how I can get Export to behave like ListAnimate?

$\endgroup$
7
  • 6
    $\begingroup$ Try a fixed PlotRange, like {{-2,2},{-2,2},{0,2}} instead of All $\endgroup$ – flinty Jul 8 '20 at 2:26
  • $\begingroup$ @flinty But what if one just needs PlotRange->All? $\endgroup$ – xzczd Jul 8 '20 at 2:49
  • 1
    $\begingroup$ @JimB The weird thing is the changing height of the z-axis doesn't cause ListAnimate the same problem where the ticks switch back and forth from the left to right side. Luckily @TimLaska's answer fixes the problem. $\endgroup$ – Chris K Jul 8 '20 at 3:21
  • 1
    $\begingroup$ @ChrisK But just using PlotRange -> {All, All, {0, 2}} gives the desired result with ListAnimate and Export (Mathematica 12.0, Windows 10). $\endgroup$ – JimB Jul 8 '20 at 3:30
  • 1
    $\begingroup$ It might be that several things reduce the jumpiness. Just adding in SphericalRegion->True reduces the jumpiness in ListAnimate. So does adding ImagePadding -> 30 (by itself without SphericalRegion). $\endgroup$ – JimB Jul 8 '20 at 3:44
9
$\begingroup$

You could try adding ImagePadding and AxesEdge to prevent the axes from jumping around.

f = Table[
   Plot3D[(1 + 
       Sin[2 π t]) E^(-(x - Sin[2 π t])^2 - (y - 
           Cos[2 π t])^2), {x, -2, 2}, {y, -2, 2}, PlotLabel -> t,
     PlotRange -> All, ViewPoint -> {-2, -2, 1}, 
    ImagePadding -> {{40, 0}, {0, 0}}, 
    AxesEdge -> {{-1, 1}, {-1, 1}, {-1, 1}}], {t, 0, 0.95, 0.05}];

ListAnimate[f]

Export["f.gif", f, "AnimationRepetitions" -> ∞]

enter image description here

$\endgroup$
4
  • $\begingroup$ Seems that ImagePadding isn't necessary? $\endgroup$ – xzczd Jul 8 '20 at 2:53
  • 1
    $\begingroup$ @xzczd Maybe. I saw some vibrations with the box when I commented it out on my windows machine (12.1.1 for Microsoft Windows (64-bit) (June 19, 2020)). I also saw some clipping of the z-axis. $\endgroup$ – Tim Laska Jul 8 '20 at 2:57
  • $\begingroup$ Perfect, this fixed both my minimal example and my real problem. Thanks! $\endgroup$ – Chris K Jul 8 '20 at 3:19
  • 1
    $\begingroup$ This solution does not visualize the height changes. Just number at the z-axis is dancing, but this is bad way. I guess the fixed PlotRange at highest value will give the best. $\endgroup$ – Rom38 Jul 8 '20 at 4:30

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.