**
我有一个关于griddata坐标的问题,它给出了typeerror:griddata()为参数'method'获得了多个值
fig=plt.figure()
ax=fig.gca(projection='3d')
yi =np.linspace(1,25)
xi =np.linspace(1,25)
X,Y =np.meshgrid(xi,yi)
for i in range(1,6)
z=df.iloc[:, i]
y=sorted(range(1,len(z)+1))
print("y=",y)
print("len y=",len(y)) #->len y = 24
a=np.array([i,i+1]*len(z)).reshape((24,2))
print("a shape=", a.shape)
print("a=",a)
print("len a=",len(a))
#-> len a = 24
b =list(itertools.chain(*zip(z,z)))
b = np.array(b).reshape((24,2))
print("b shape=", b.shape)
#-> len b = 24
Z = griddata(a,y,b,(xi,yi),method="nearest")
并给出错误
Z = griddata(a,y,b,(X,Y),method =“ nearest”) TypeError:griddata()为参数“方法”获得了多个值
X坐标包含[1,2],[2,3],y坐标包含1到24,Z坐标包含一些值,并且每列为24个值 我无法解决插值错误
谢谢**
答案 0 :(得分:0)
好的,我解决了。 scipy-interpolate griddata也使用[:,1]数组,因此它不能接受我的2D数组作为点
工作代码在这里,谢谢
fig=plt.figure()
ax=fig.gca(projection='3d')
for i in range(1,6):
z=df.iloc[:, i]
y=np.array(sorted(list(range(1,len(z)+1))*2)).reshape((48,1))
a=np.array([i,i+1.2]*len(z)).reshape((48,1))
points = np.concatenate((a, y), axis=1)
b =list(itertools.chain(*zip(z,z)))
b = np.array(b).reshape((48,1))
yi =np.linspace(min(a),max(a))
xi =np.linspace(min(y),max(y))
X,Y =np.meshgrid(yi,xi)
Z = griddata(points,b,(yi,xi),method="linear")