Skip to content

Instantly share code, notes, and snippets.

@sabopy
Last active August 3, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabopy/c3d872d9564e5d914b25e1a8c029bd2d to your computer and use it in GitHub Desktop.
Save sabopy/c3d872d9564e5d914b25e1a8c029bd2d to your computer and use it in GitHub Desktop.
%matplotlib widget
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from ipywidgets import interactive,IntSlider,VBox
from IPython.display import display
# Make data
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z,color="C8",rcount=100, ccount=100, antialiased=False)
x_a = IntSlider(min=0, max=10,value=4,step=1, description="x: ",
orientation='horizontal')
y_a = IntSlider(min=0, max=10,value=4,step=1,description="y: ",
orientation='horizontal')
z_a = IntSlider(min=0, max=10,value=3,step=1, description="z: ",
orientation='horizontal')
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
def f(x_a,y_a,z_a):
ax.set_box_aspect((x_a, y_a,z_a))
w = interactive(f,x_a=x_a,y_a=y_a,z_a=z_a)
ui = VBox([x_a, y_a,z_a])
display(ui)
#version
import matplotlib
print(matplotlib.__version__)
3.3.0
import ipywidgets
print(ipywidgets.__version__)
7.5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment