6
$\begingroup$

I know this is not the first question on creating an animation of a 3D plot, but I found no answer to the following question: How can I create an animated rotating plot with axes labels that are readable? What I currently have doesn't look good. The axes colors are weird and irregular, the cube rotates not around its center and the axes labels jump around to different axes.

enter image description here

My code currently is adapted from this answer

anim = Table[
     RegionPlot3D[
      0 <= x <= y <= z <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, 
      PlotRange -> {{0, 1.2}, {0, 1.2}, {0, 1.2}}, 
      PlotStyle -> Opacity[0.7], Boxed -> False, 
      ViewCenter -> {0.5, 0.5, 0.5}, 
      ViewVector -> {5 Sin[t], 5 Cos[t], 0} ], {t, 0, 2*Pi, 
      Pi/30}]; Export["animated.gif", anim]

I want it to look similar to the following. Also the plot should rotate exactly once around its axis so that the loop of the gif isn't noticeable. Great would be if there was one variable which allows to quickly change the speed of the rotation without breaking that it rotates exactly once.

enter image description here

$\endgroup$
6
$\begingroup$

It all comes down to first inspect if the frames you create are of good quality. I would in this step create an image from your plot because then you directly see what will be encoded in the gif.

I adjusted three things

  1. Opacity and mesh-lines look somehow not really nice together on my machine. Your example is different. The meshed surface is fully opaque and only the non-meshed sides have transparency.
  2. You definitely need to adjust PlotPoints and MaxRecursion. Your region is highly affected by the way RegionPlot3D samples the domain.
  3. I'm using SphericalRegion because it removes the "jumping around" in the animation.

The code needs some time because of the higher quality, so get a tea during the creation of all frames

makePlot[t_?NumericQ] := 
 Rasterize[
  RegionPlot3D[0 <= x <= y <= z <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
    PlotRange -> {{0, 1.2}, {0, 1.2}, {0, 1.2}},
   ViewCenter -> {0.5, 0.5, 0.5}, 
   ViewVector -> {5 Sin[t], 5 Cos[t], 2 Sin[t] + 1/2},
   SphericalRegion -> True,
   MaxRecursion -> 5, PlotPoints -> 150
   ]]

anim = ParallelTable[makePlot[t], {t, 0, 2*Pi, Pi/30}];
Export["~/tmp/animated.gif", anim, "AnimationRepetitions" -> Infinity]

enter image description here

On OS X

With a Mac there seems to be some trial and error involved. It turns out that you have to adjust the MeshStyle make it look OK. The value of the thickness depends on the image size you are creating:

makePlot[t_?NumericQ] := 
 Rasterize[
  RegionPlot3D[0 <= x <= y <= z <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
    PlotRange -> {{0, 1.2}, {0, 1.2}, {0, 1.2}}, 
   ViewCenter -> {0.5, 0.5, 0.5}, 
   ViewVector -> {5 Sin[t], 5 Cos[t], 2 Sin[t] + 1/2}, 
   SphericalRegion -> True, MaxRecursion -> 5, PlotPoints -> 150,
   MeshStyle -> AbsoluteThickness[1]],
  ImageResolution -> 150
  ]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks! Your result looks like I intended. What's weird though is when I run your exact code on my machine, my GIF still doesn't look good: i.imgur.com/uHd3x2F.gif I get the same artifacts on the axes as before. This leads me to believe that this has something to do with my system, though I can't see why that would be. I'm using the latest version 11.3 of Mathematica (student edition) and the latest macOS 10.13.4 on a recent MacBook Pro. $\endgroup$ – philmcole May 28 '18 at 7:22
  • $\begingroup$ Can you try the following trick? In the Rasterize, you an explicit option RasterSize -> 320 and then you wrap the whole Rasterize call with ImageResize[..., 300]. In addition to that, please check what your settings for Preferences -> Appearance -> Graphics are. $\endgroup$ – halirutan May 28 '18 at 9:11
  • $\begingroup$ Tried it, unfortunately no big difference in the appearance. It took only much longer and the file size grew from ~800KB to 1MB. Also in the Graphics settings my slider is set to Highest Quality. Actually I've never changed anything in Mathematica's settings so they are all on the default setting. The only explanation that comes to my mind is that maybe Wolfram chose to limit the capabilities of the student version? $\endgroup$ – philmcole May 28 '18 at 10:46
  • $\begingroup$ @philmcole I tested it on my OS X and it seems some fiddling helps. $\endgroup$ – halirutan May 28 '18 at 11:27
  • $\begingroup$ @philmcole I updated my answer with the exact code I used under OSX. I thought you have seen this. $\endgroup$ – halirutan May 28 '18 at 12:52

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.