analogy to scipy.interpolate.griddata?

≡放荡痞女 提交于 2019-12-03 03:23:25

This is a function I use for this kind of stuff:

from numpy import linspace, meshgrid

def grid(x, y, z, resX=100, resY=100):
    "Convert 3 column data to matplotlib grid"
    xi = linspace(min(x), max(x), resX)
    yi = linspace(min(y), max(y), resY)
    Z = griddata(x, y, z, xi, yi)
    X, Y = meshgrid(xi, yi)
    return X, Y, Z

Then use it like this:

  X, Y, Z = grid(x, y, z)

Scipy has documentation with a specific example of how to use scipy.interpolate.griddata and they explain exactly what you are asking for. Look here: http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html

In short, you do this the get the "grid data":

grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]

This would make a 100x200 grid which ranges from 0 to 1 in both x- and y-direction.

grid_x, grid_y = np.mgrid[-10:10:51j, 0:2:20j]

This would make a 51x20 grid which ranges from -10 to 10 in x-direction and 0 to 2 in y-direction.

Now you have to correct input for scipy.interpolate.griddata.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!