Python,两条曲线之间的Surface,matplotlib

时间:2017-03-15 21:29:27

标签: python numpy matplotlib

我有两个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中绘制连接这些线的曲面,以获得类似的结果:

https://pythonprogramming.net/static/images/dataviz/wire-frame-plane-tutorial-matplotlib-python-1024x682.png

如何在python中使用matplotlib执行此操作?

谢谢!

1 个答案:

答案 0 :(得分:0)

您创建合理网格的点数太少了。

您可以使用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()

enter image description here

但结果并不吸引人。