Good Fibrations math is art · A blog since 2013. Scraps of a playground annealing in the dark.
Science tutorial codematlabanimationvideowriter3d-plottinglorenz-attractor

Matlab: Smooth Rotating Animation for Line Plots

I recently became stuck trying to create an animation which consists of a smooth rotation of a viewpoint around the Lorenz attractor. Methods I use for changing viewpoints with respect to surface objects were creating jerky, lagging animations when applied to my line plot.

This will work for any 3D line plot:

plot3(x,y,z);
axis vis3d
fps = 60; sec = 10;
vidObj = VideoWriter('plotrotation.avi');
vidObj.Quality = 100;
vidObj.FrameRate = fps;
open(vidObj);
for i=1:fps*sec
    camorbit(0.9,-0.1);
    writeVideo(vidObj,getframe(gcf));
end
close(vidObj);

This results in the following smooth animation:

More in Science

Comments from the old blog (1)

Recovered from the Wayback Machine of the old site after my back-up servers got black-hatted.

  1. Thank You!!!

    You are a God amongst men!!! I have been trying for over a week to get a 3D plot to rotate smoothly. It kept jumping around as it rotated, zooming in and out, giving weird perspectives, etc. etc. I’ve scoured every Stackoverflow and mathworks post on the issue, consulted every matlab coder I know, NO ONE could figure it out.

    The solution? “axis vis3d”

    I have no idea why those 9 characters solved all of the world’s problems but they did. Thanks.