我正在使用scipy.interpolate(),并使用与示例类似的方法来创建地图。因此,我需要在另一个软件中使用插值曲面的X,Y,Z值。如何将以网格格式存储的数据导出为X,Y,Z值?非常感谢您的建议...
示例
'''将numpy导入为np
import scipy.interpolate
import matplotlib.pyplot as plt
np.random.seed(1234)
x, y, z = np.random.random((3, 10))
interp = scipy.interpolate.Rbf(x, y, z, function='thin_plate')
yi, xi = np.mgrid[0:1:100j, 0:1:100j]
zi = interp(xi, yi)
plt.plot(x, y, 'ko')
plt.imshow(zi.T, extent=[0, 1, 1, 0], cmap='gist_earth')
plt.colorbar()
plt.show()
'''
您可以通过嵌套循环将X Y和Z值作为列表获取:
coordinateList = np.zeros([3,100*100])
for x in range(100):
for y in range(100):
coordinateList[0,x*100+y]=xi[x,y]
coordinateList[1,x*100+y]=yi[x,y]
coordinateList[2,x*100+y]=zi[x,y]
对于导出,您可以使用相同的循环,但是除了将值存储在numpy数组中之外,您还可以将值写入X,Y和Z之间的逗号到文本文件中,然后导入到像excel这样的程序中CSV文件。