Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Richard
- from mpl_toolkits.mplot3d import Axes3D
- %matplotlib notebook
- import matplotlib.pyplot as plt
- import numpy as np
- from mpl_toolkits.mplot3d import proj3d
- from matplotlib.patches import FancyArrowPatch
- class Arrow3D(FancyArrowPatch):
- def __init__(self, xs, ys, zs, *args, **kwargs):
- FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
- self._verts3d = xs, ys, zs
- def draw(self, renderer):
- xs3d, ys3d, zs3d = self._verts3d
- xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
- self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
- FancyArrowPatch.draw(self, renderer)
- fig = plt.figure()
- ax = fig.add_subplot(111, projection='3d')
- '''Prepare the 2D domain: x from -5 to 5 and y from -5 to 5'''
- x,y = np.meshgrid(np.linspace(-10,10,21),np.linspace(-10,10,21))
- t = np.linspace(-5,5,21)
- x = t
- y = 1-t
- z = 3+t**2
- '''Plot the parametric equation'''
- ax.plot(x,y,z)
- '''Prepare the 2D domain: x from -5 to 5 and y from -5 to 5'''
- x,y = np.meshgrid(np.linspace(-5,5,21),np.linspace(-5,5,21))
- s = np.linspace(-5,5,21)
- x2 = 3-s
- y2 = s-2
- z2 = s**2
- '''Plot the parametric equation'''
- ax.plot(x2,y2,z2)
- a = Arrow3D([0,0],[0,0],[0,1], mutation_scale=20, lw=3, arrowstyle="-|>", color="r")
- ax.add_artist(a)
- b = Arrow3D([0,1],[0,1],[0,1], mutation_scale=20, lw=3, arrowstyle="-|>", color="b")
- ax.add_artist(b)
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_zlabel('z')
- ax.set_title('Plot of Two Curves')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement