尝试绘制一条线,将 3D 子图上的点连接到另一个 3D 子图。在 2D 中,使用 ConnectionPatch 很容易做到这一点。我试图从这里模仿 Arrow3D 类,但没有运气。
在这一点上,即使只是一个变通方法,我也很高兴。例如,在下面代码生成的图中,我想连接两个绿点。
def cylinder(r, n):
'''
Returns the unit cylinder that corresponds to the curve r.
INPUTS: r - a vector of radii
n - number of coordinates to return for each element in r
OUTPUTS: x,y,z - coordinates of points
'''
# ensure that r is a column vector
r = np.atleast_2d(r)
r_rows, r_cols = r.shape
if r_cols > r_rows:
r = r.T
# find points along x and y axes
points = np.linspace(0, 2*np.pi, n+1)
x = np.cos(points)*r
y = np.sin(points)*r
# find points along z axis
rpoints = np.atleast_2d(np.linspace(0, 1, len(r)))
z = np.ones((1, n+1))*rpoints.T
return x, y, z
#---------------------------------------
# 3D example
#---------------------------------------
fig = plt.figure()
# top figure
ax = fig.add_subplot(2,1,1, projection='3d')
x,y,z = cylinder(np.linspace(2,1,num=10), 40)
for i in range(len(z)):
ax.plot(x[i], y[i], z[i], 'c')
ax.plot([2], [0], [0],'go')
# bottom figure
ax2 = fig.add_subplot(2,1,2, projection='3d')
x,y,z = cylinder(np.linspace(0,1,num=10), 40)
for i in range(len(z)):
ax2.plot(x[i], y[i], z[i], 'r')
ax2.plot([1], [0], [1],'go')
plt.show()