Advertisement
UF6

Group Project 2, Problem 14

UF6
May 4th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import matplotlib
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. %matplotlib inline
  5. from mpl_toolkits.mplot3d.axes3d import Axes3D
  6. %matplotlib notebook
  7. import matplotlib.pyplot as plt
  8. import numpy as np
  9.  
  10. '''Prepare the figure container'''
  11. fig = plt.figure()
  12. ax = fig.add_subplot(111, projection='3d')
  13.  
  14. '''Prepare the 2D domain: x from -1 to 1 and y from -1 to 1'''
  15. x,y = np.meshgrid(np.linspace(-1,1,41),np.linspace(-1,1,41))
  16. t = np.linspace(0, 2*np.pi)
  17. X = np.cos(t)
  18. Y = np.sin(t)
  19. z1 = x**2 - y**2
  20.  
  21. z3 = 2*X**2 - 1
  22.  
  23. x2=np.linspace(-1,1,40)
  24. z2=np.linspace(-2,2,40)
  25.  
  26. X2, Z2=np.meshgrid(x2,z2)
  27. Y2=np.sqrt(1-X2**2)
  28.  
  29. ax.plot_wireframe(X2,Y2,Z2)
  30. ax.plot_wireframe(X2,-Y2,Z2)
  31.  
  32. '''Plot the surface'''
  33. ax.plot_surface(x,y,z1)
  34.  
  35. ax.plot(X,Y,z3, color="red")
  36.                
  37. '''Set all labels, view, and then plot'''
  38. ax.set_xlabel('x')
  39. ax.set_ylabel('y')
  40. ax.set_zlabel('f(x,y)')
  41. ax.set_xticks([-1,-0.5,0,0.5,1])
  42. ax.set_yticks([-1,-0.5,0,0.5,1])
  43. ax.set_zticks([-1,-0.5,0,0.5,1])
  44. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement