Tuesday, 20 August 2013

Animate a rotating 3D graph in matplotlib

Animate a rotating 3D graph in matplotlib

I have a scatter plot set up and plotted the way I want it, and I want to
create an .mp4 video of the figure rotating in space, as if I had used
plt.show() and dragged the viewpoint around.
This answer is almost exactly what I want, except to save a movie I would
have to manually call into FFMpeg with a folder of images. Instead of
saving individual frames I'd prefer to use Matplotlib's built in animation
support. Code reproduced below:
from mpl_toolkits.mplot3d import Axes3D
ax = Axes3D(fig)
ax.scatter(xx,yy,zz, marker='o', s=20, c="goldenrod", alpha=0.6)
for ii in xrange(0,360,1):
ax.view_init(elev=10., azim=ii)
savefig("movie"%ii+".png")

No comments:

Post a Comment