I'm plotting curves in 3D using matplotlib and I would like to project those onto the 3D grid planes (XY, XZ, & YZ) to get a better feel for the shape. My current code results in the attached image, where you can see that the projected lines are slightly off from the actual grid lines.
I'm hoping there's some flag buried in the documentation I've looked over, but are there any suggestions to more precisely align my projections with the 3D grid lines without some sort of "hacky" method?
TIA
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# curve definition
num_verts = 11
start = np.array([0., 0., 6.], dtype = np.float64)
stop = np.array([10., 0., 6.], dtype = np.float64)
delta = (stop - start) / (num_verts - 1)
curve = np.array([start + delta * i for i in range(num_verts)], dtype = np.float64)
# plot curve
xl = (-1, 11)
yl = (-5, 5)
zl = (0, 11)
fig = plt.figure(figsize=(16,10))
ax = fig.add_subplot(111, projection="3d")
ax.plot(curve[:,0],curve[:,1],curve[:,2],linewidth=4,label="Curve")
ax.set(title="Curve with projections",xlabel='x',ylabel='y',zlabel='z',xlim=xl,ylim=yl,zlim=zl)
# xy projection #
ax.plot(curve[:,0],curve[:,1],zs=zl[0],zdir='z',color='dimgray',linewidth=4,label="Centerline projections")
# yz projection #
ax.plot(curve[:,1],curve[:,2],zs=xl[0],zdir='x',color='dimgray',linewidth=4)
# xz projection #
ax.plot(curve[:,0],curve[:,2],zs=yl[1],zdir='y',color='dimgray',linewidth=4)
plt.legend()
plt.show()
EDIT: The "hacky" way I found is to offset the projections by 2% of the width of the dimensions limits (e.g. xlim). Haven't tested it for robustness so YMMV.
# xy projection #
ax.plot(curve[:,0],curve[:,1],zs=zl[0] - (zl[1] - zl[0])*0.02,zdir='z',color='dimgray',linewidth=4,label="Centerline projections")
# yz projection #
ax.plot(curve[:,1],curve[:,2],zs=xl[0] - (xl[1] - xl[0])*0.02,zdir='x',color='dimgray',linewidth=4)
# xz projection #
ax.plot(curve[:,0],curve[:,2],zs=yl[1] + (yl[1] - yl[0])*0.02,zdir='y',color='dimgray',linewidth=4)

