|
3 | 3 | Rotating a 3D plot
|
4 | 4 | ==================
|
5 | 5 |
|
6 |
| -A very simple animation of a rotating 3D plot. |
| 6 | +A very simple animation of a rotating 3D plot about all 3 axes. |
7 | 7 |
|
8 | 8 | See wire3d_animation_demo for another simple example of animating a 3D plot.
|
9 | 9 |
|
|
17 | 17 | fig=plt.figure()
|
18 | 18 | ax=fig.add_subplot(projection='3d')
|
19 | 19 |
|
20 |
| -#load sometest datafor demonstrationand plot a wireframe |
21 |
| -X,Y,Z=axes3d.get_test_data(0.1) |
22 |
| -ax.plot_wireframe(X,Y,Z,rstride=5,cstride=5) |
| 20 | +#Grab someexample data and plot abasicwireframe. |
| 21 | +X,Y,Z=axes3d.get_test_data(0.05) |
| 22 | +ax.plot_wireframe(X,Y,Z,rstride=10,cstride=10) |
23 | 23 |
|
24 |
| -# rotate the axes and update |
25 |
| -forangleinrange(0,360): |
26 |
| -ax.view_init(30,angle,0) |
| 24 | +# Set the axis labels |
| 25 | +ax.set_xlabel('x') |
| 26 | +ax.set_ylabel('y') |
| 27 | +ax.set_zlabel('z') |
| 28 | + |
| 29 | +# Rotate the axes and update |
| 30 | +forangleinrange(0,360*4+1): |
| 31 | +# Normalize the angle to the range [-180, 180] |
| 32 | +angle_norm= (angle+180)%360-180 |
| 33 | + |
| 34 | +# Cycle through a full rotation of the elevation, azimuth, roll, then all |
| 35 | +elev=azim=roll=0 |
| 36 | +ifangle<=360: |
| 37 | +elev=angle_norm |
| 38 | +elifangle<=360*2: |
| 39 | +azim=angle_norm |
| 40 | +elifangle<=360*3: |
| 41 | +roll=angle_norm |
| 42 | +else: |
| 43 | +elev=azim=roll=angle_norm |
| 44 | + |
| 45 | +# Update the axis view and title |
| 46 | +ax.view_init(elev,azim,roll) |
| 47 | +plt.title('Elevation: %d°, Azimuth: %d°, Roll: %d°'% (elev,azim,roll)) |
27 | 48 | plt.draw()
|
28 | 49 | plt.pause(.001)
|