Advertisement
UF6

Group Project 2, Project 15

UF6
May 2nd, 2016
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. #Richard
  2. from mpl_toolkits.mplot3d import Axes3D
  3. %matplotlib notebook
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. from mpl_toolkits.mplot3d import proj3d
  7. from matplotlib.patches import FancyArrowPatch
  8.  
  9. class Arrow3D(FancyArrowPatch):
  10.     def __init__(self, xs, ys, zs, *args, **kwargs):
  11.         FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
  12.         self._verts3d = xs, ys, zs
  13.  
  14.     def draw(self, renderer):
  15.         xs3d, ys3d, zs3d = self._verts3d
  16.         xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
  17.         self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
  18.         FancyArrowPatch.draw(self, renderer)
  19.  
  20. fig = plt.figure()
  21. ax = fig.add_subplot(111, projection='3d')
  22.  
  23. '''Prepare the 2D domain: x from -5 to 5 and y from -5 to 5'''
  24. x,y = np.meshgrid(np.linspace(-10,10,21),np.linspace(-10,10,21))
  25.  
  26. t = np.linspace(-5,5,21)
  27. x = t
  28. y = 1-t
  29. z = 3+t**2
  30.  
  31.  
  32. '''Plot the parametric equation'''
  33. ax.plot(x,y,z)
  34.  
  35. '''Prepare the 2D domain: x from -5 to 5 and y from -5 to 5'''
  36. x,y = np.meshgrid(np.linspace(-5,5,21),np.linspace(-5,5,21))
  37.  
  38. s = np.linspace(-5,5,21)
  39. x2 = 3-s
  40. y2 = s-2
  41. z2 = s**2
  42.  
  43. '''Plot the parametric equation'''
  44. ax.plot(x2,y2,z2)
  45.  
  46. a = Arrow3D([0,0],[0,0],[0,1], mutation_scale=20, lw=3, arrowstyle="-|>", color="r")
  47. ax.add_artist(a)
  48.  
  49. b = Arrow3D([0,1],[0,1],[0,1], mutation_scale=20, lw=3, arrowstyle="-|>", color="b")
  50. ax.add_artist(b)
  51.  
  52. ax.set_xlabel('x')
  53. ax.set_ylabel('y')
  54. ax.set_zlabel('z')
  55. ax.set_title('Plot of Two Curves')
  56.  
  57.  
  58.  
  59. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement