The scipy.interpolate.griddata analogy?

I want to interpolate this cloud of 3D points:

I looked at scipy.interpolate.griddata, and the result is exactly what I need, but as I understand it, I need to enter "griddata", which means something like x = [[0,0,0],[1,1,1],[2,2,2]] .

But my 3D point cloud does not have this kind of grid. The x, y values โ€‹โ€‹do not behave like a grid. In any case, for each x, y-value, there is only one z-value. *

So, is there an alternative to scipy.interpolate.griddata for my no-in-grid-point-cloud?

* Editing: โ€œNo gridโ€ means my input looks like this:

 x = [0,4,17] y = [-7,25,116] z = [50,112,47] 
+7
python scipy interpolation
source share
2 answers

This is the function I use for this kind of thing:

 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 as follows:

  X, Y, Z = grid(x, y, z) 
+6
source share

Scipy has documentation with a specific use case for scipy.interpolate.griddata, and they explain exactly what you are asking for. See here: http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html

In short, you do this to get โ€œgrid dataโ€:

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

This would create a 100x200 grid that ranges from 0 to 1 in both x and y directions.

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

This would create a 51x20 grid that ranges from -10 to 10 in the x direction and from 0 to 2 in the y direction.

Now you need to fix the input for scipy.interpolate.griddata.

0
source share

All Articles