From 81eb25327f26fb0a1a8ded429be94e81cc03d766 Mon Sep 17 00:00:00 2001 From: Scott Shambaugh Date: Tue, 23 Nov 2021 19:30:53 -0700 Subject: [PATCH] Update rotate-axes3d gallery example Rename gallery example for clarity - this animation does not do any rotating --- examples/mplot3d/rotate_axes3d_sgskip.py | 36 +++++++++++++++++---- examples/mplot3d/wire3d_animation_sgskip.py | 6 ++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/examples/mplot3d/rotate_axes3d_sgskip.py b/examples/mplot3d/rotate_axes3d_sgskip.py index be8adf3c29a0..6026c63621c0 100644 --- a/examples/mplot3d/rotate_axes3d_sgskip.py +++ b/examples/mplot3d/rotate_axes3d_sgskip.py @@ -3,7 +3,7 @@ Rotating a 3D plot ================== -A very simple animation of a rotating 3D plot. +A very simple animation of a rotating 3D plot about all 3 axes. See wire3d_animation_demo for another simple example of animating a 3D plot. @@ -17,12 +17,34 @@ fig = plt.figure() ax = fig.add_subplot(projection='3d') -# load some test data for demonstration and plot a wireframe -X, Y, Z = axes3d.get_test_data(0.1) -ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5) +# 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 labels +ax.set_xlabel('x') +ax.set_ylabel('y') +ax.set_zlabel('z') + +# Rotate the axes and update +for angle in range(0, 360*4 + 1): + # Normalize the angle to the range [-180, 180] for display + angle_norm = (angle + 180) % 360 - 180 + + # Cycle through a full rotation of elevation, then azimuth, roll, and all + elev = azim = roll = 0 + if angle <= 360: + elev = angle_norm + elif angle <= 360*2: + azim = angle_norm + elif angle <= 360*3: + roll = angle_norm + else: + elev = azim = roll = angle_norm + + # Update the axis view and title + ax.view_init(elev, azim, roll) + plt.title('Elevation: %d°, Azimuth: %d°, Roll: %d°' % (elev, azim, roll)) -# rotate the axes and update -for angle in range(0, 360): - ax.view_init(30, angle) plt.draw() plt.pause(.001) diff --git a/examples/mplot3d/wire3d_animation_sgskip.py b/examples/mplot3d/wire3d_animation_sgskip.py index bc4cccf20a2c..b8c801bd1029 100644 --- a/examples/mplot3d/wire3d_animation_sgskip.py +++ b/examples/mplot3d/wire3d_animation_sgskip.py @@ -1,7 +1,7 @@ """ -========================== -Rotating 3D wireframe plot -========================== +============================= +Animating a 3D wireframe plot +============================= A very simple 'animation' of a 3D plot. See also rotate_axes3d_demo.