Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be94172

Browse files
authored
Merge pull request #21737 from scottshambaugh/rotate-3d-plot-gallery
Update the "Rotating a 3D plot" gallery example to show all 3 rotation axes
2 parents fc4f0cc + 6ba5cb8 commit be94172

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

examples/mplot3d/rotate_axes3d_sgskip.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rotating a 3D plot
44
==================
55
6-
A very simple animation of a rotating 3D plot.
6+
A very simple animation of a rotating 3D plot about all 3 axes.
77
88
See wire3d_animation_demo for another simple example of animating a 3D plot.
99
@@ -17,12 +17,34 @@
1717
fig = plt.figure()
1818
ax = fig.add_subplot(projection='3d')
1919

20-
# load some test data for demonstration and 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 some example data and plot a basic wireframe.
21+
X, Y, Z = axes3d.get_test_data(0.05)
22+
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
23+
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+
for angle in range(0, 360*4 + 1):
31+
# Normalize the angle to the range [-180, 180] for display
32+
angle_norm = (angle + 180) % 360 - 180
33+
34+
# Cycle through a full rotation of elevation, then azimuth, roll, and all
35+
elev = azim = roll = 0
36+
if angle <= 360:
37+
elev = angle_norm
38+
elif angle <= 360*2:
39+
azim = angle_norm
40+
elif angle <= 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))
2348

24-
# rotate the axes and update
25-
for angle in range(0, 360):
26-
ax.view_init(30, angle, 0)
2749
plt.draw()
2850
plt.pause(.001)

examples/mplot3d/wire3d_animation_sgskip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
==========================
3-
Rotating 3D wireframe plot
4-
==========================
2+
=============================
3+
Animating a 3D wireframe plot
4+
=============================
55
66
A very simple 'animation' of a 3D plot. See also rotate_axes3d_demo.
77

0 commit comments

Comments
 (0)