Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib
- import matplotlib.pyplot as plt
- import numpy as np
- %matplotlib inline
- from mpl_toolkits.mplot3d.axes3d import Axes3D
- %matplotlib notebook
- import matplotlib.pyplot as plt
- import numpy as np
- '''Prepare the figure container'''
- fig = plt.figure()
- ax = fig.add_subplot(111, projection='3d')
- '''Prepare the 2D domain: x from -1 to 1 and y from -1 to 1'''
- x,y = np.meshgrid(np.linspace(-1,1,41),np.linspace(-1,1,41))
- t = np.linspace(0, 2*np.pi)
- X = np.cos(t)
- Y = np.sin(t)
- z1 = x**2 - y**2
- z3 = 2*X**2 - 1
- x2=np.linspace(-1,1,40)
- z2=np.linspace(-2,2,40)
- X2, Z2=np.meshgrid(x2,z2)
- Y2=np.sqrt(1-X2**2)
- ax.plot_wireframe(X2,Y2,Z2)
- ax.plot_wireframe(X2,-Y2,Z2)
- '''Plot the surface'''
- ax.plot_surface(x,y,z1)
- ax.plot(X,Y,z3, color="red")
- '''Set all labels, view, and then plot'''
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_zlabel('f(x,y)')
- ax.set_xticks([-1,-0.5,0,0.5,1])
- ax.set_yticks([-1,-0.5,0,0.5,1])
- ax.set_zticks([-1,-0.5,0,0.5,1])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement