我有两个numpy数组来表示3d空间中的一条线(注意
# this represents line 1
x1 = [1,2,3]
y1 = [1,4,4]
z1 = [1,1,1]
# this represents line 2
x2 = [1,2,3,4]
y2 = [1,4,5,7]
z2 = [10,10,10]
# Notice that the array representing line 1 and the array representing line 2 have different sizes
# I am currently plotting the aforementioned '3D' lines as follows
ax.plot(x1,y1,z1)
ax.plot(x2,y2,z2)
我想在3D中绘制连接这些线的曲面,以获得如下所示:
我如何在python中使用matplotlib来做这件事?
谢谢!
发布于 2017-03-16 16:20:26
您的点太少,无法创建一个合理的网格。
您所能做的就是使用plot_trisurf
绘制点。
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# this represents line 1
x1 = [1,2,3]
y1 = [1,4,4]
z1 = [1,1,1]
# this represents line 2
x2 = [1,2,3,4]
y2 = [1,4,5,7]
z2 = [10,10,10,10]
# Notice that the array representing line 1 and the array representing line 2 have different sizes
# I am currently plotting the aforementioned '3D' lines as follows
ax.plot(x1,y1,z1)
ax.plot(x2,y2,z2)
x=np.array([1,2,3, 1,2,3,4])
y=np.array([1,4,4, 1,4,5,7])
z=np.array([1,1,1, 10,10,10,10])
ax.plot_trisurf(x,y,z )
plt.show()
但结果并不是真正有吸引力。
https://stackoverflow.com/questions/42821036
复制相似问题