I couldn't find a simple example, so I made it as a memo.
See below for detailed instructions and setup.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from ipywidgets import interact, FloatSlider, IntSlider
import numpy as np
x = y = np.arange(-20, 20, 0.5)
X, Y = np.meshgrid(x, y)
Z = X*X + 2 * Y*Y
@interact(elev=IntSlider(min=-180, max=180, step=10, value=30, continuous_update=False),
azim=IntSlider(min=-180, max=180, step=10, value=30, continuous_update=False))
def plot_3d(elev, azim):
#Figure settings
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
#Display 3D graph
ax.plot_surface(X, Y, Z)
#Set the initial value of the viewing direction of the 3D graph
ax.view_init(elev=elev, azim=azim)
plt.show()
Recommended Posts