rmas - 10 months ago 68

Python Question

I am plotting a curve in a 3D space using three vectors X, Y and Z.

How can I draw the projections of the curve onto the planes XOY, XOZ, YOZ?

`import matplotlib.pylab as plt`

from mpl_toolkits.mplot3d.axes3d import Axes3D

fig = plt.figure()

ax = Axes3D(fig)

X = [4, 2, 7, 4]

Y = [7, 4, 9, 6]

Z = [9, 6, 10, 3]

ax.plot(X, Y, Z, 'b-', linewidth=4, label='parametric curve')

plt.show()

Answer Source

Since you are simply plotting points in 3D space (meaning that even though you call it parametric, your curve is not parametric), you get the "projection" by just setting the respective dimension to zero.

For example, to plot on th XoY plane, you'd neglect the `Z`

component and use

```
zeros = [0,0,0,0]
plt.plot(X,Y,zeros)
```

In total this would look like

```
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
X = [4, 2, 7, 4]
Y = [7, 4, 9, 6]
Z = [9, 6, 10, 3]
ax.plot(X, Y, Z, 'b-', linewidth=4, label='curve')
null = [0]*len(Z)
ax.plot(null, Y, Z)
ax.plot(X,null, Z)
ax.plot(X, Y, null)
plt.show()
```