2017-03-15 105 views
0

我有代表在3D空间中的线两条numpy的阵列(注意Python中,两条曲线之间的表面,matplotlib

# 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

我怎样才能做到这一点使用matplotlib的python?

谢谢!

回答

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

但结果是不是真的有吸引力。