简体   繁体   English

如何使用scipy.interpolate中的griddata

[英]How to use griddata from scipy.interpolate

I have a three-column (x-pixel, y-pixel, z-value) data with one million lines. 我有一个三列(x像素,y像素,z值)数据,有一百万行。 The data is from an image and there are duplicated z-values. 数据来自图像,并且存在重复的z值。 Now I need to make a surface plot. 现在我需要制作表面图。 This image is a perfect example. 这个图像是一个很好的例子。 But now the output image is null. 但现在输出图像为空。 Could someone check the code please? 有人可以查一下代码吗?

import numpy as np
from enthought.mayavi import mlab
from scipy.interpolate import griddata
x,y,z = np.loadtxt('test.csv',delimiter=',',usecols=(0,1,2),unpack=True) 
xi,yi = np.mgrid[0:3000:3000j, 0:3000:3000j]
zi = griddata((x, y), z, (xi, yi),method='linear')
mlab.surf(xi,yi,zi)
mlab.show()

I can't check the code without having the data, but I suspect that the problem is that you are using the default fill_value=nan as a griddata argument, so if you have gridded points that extend beyond the space of the (x,y) points, there are NaNs in the grid, which mlab may not be able to handle (matplotlib doesn't easily). 我不能在没有数据的情况下检查代码,但我怀疑问题是你使用默认的fill_value=nan作为griddata参数,所以如果你有网格点超出(x,y)的空间)点,网格中有NaNs,mlab可能无法处理(matplotlib不容易)。 Try setting fill_value=0 or another suitable real number. 尝试设置fill_value=0或其他合适的实数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM