Note
Go to the endto download the full example code.
Rotating a 3D plot#
A very simple animation of a rotating 3D plot about all three axes.
SeeAnimate a 3D wireframe plot for another example of animating a 3D plot.
(This example is skipped when building the documentation gallery because itintentionally takes a long time to run)
importmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportaxes3dfig=plt.figure()ax=fig.add_subplot(projection='3d')# Grab some example data and plot a basic wireframe.X,Y,Z=axes3d.get_test_data(0.05)ax.plot_wireframe(X,Y,Z,rstride=10,cstride=10)# Set the axis labelsax.set_xlabel('x')ax.set_ylabel('y')ax.set_zlabel('z')# Rotate the axes and updateforangleinrange(0,360*4+1):# Normalize the angle to the range [-180, 180] for displayangle_norm=(angle+180)%360-180# Cycle through a full rotation of elevation, then azimuth, roll, and allelev=azim=roll=0ifangle<=360:elev=angle_normelifangle<=360*2:azim=angle_normelifangle<=360*3:roll=angle_normelse:elev=azim=roll=angle_norm# Update the axis view and titleax.view_init(elev,azim,roll)plt.title('Elevation:%d°, Azimuth:%d°, Roll:%d°'%(elev,azim,roll))plt.draw()plt.pause(.001)
Tags:plot-type: 3Dcomponent: animationlevel: advancedinternal: high-bandwidth