Interpolate over a 2-D grid.
x, y and z are arrays of values used to approximate some function f: z = f(x, y). This class returns a function whose call method uses spline interpolation to find the value of new points.
Parameters : | x, y : 1-D ndarrays
z : 1-D ndarray
kind : {‘linear’, ‘cubic’, ‘quintic’}, optional
copy : bool, optional
bounds_error : bool, optional
fill_value : number, optional
|
---|
Notes
The minimum number of data points required along the interpolation axis is (k+1)**2, with k=1 for linear, k=3 for cubic and k=5 for quintic interpolation.
The interpolator is constructed by bisplrep, with a smoothing factor of 0. If more control over smoothing is needed, bisplrep should be used directly.
Examples
Construct a 2-D grid and interpolate on it:
>>> x = np.arange(-5.01, 5.01, 0.25)
>>> y = np.arange(-5.01, 5.01, 0.25)
>>> xx, yy = np.meshgrid(x, y)
>>> z = np.sin(xx**2+yy**2)
>>> f = sp.interpolate.interp2d(x, y, z, kind='cubic')
Now use the obtained interpolation function and plot the result:
>>> xnew = np.arange(-5.01, 5.01, 1e-2)
>>> ynew = np.arange(-5.01, 5.01, 1e-2)
>>> znew = f(xnew, ynew)
>>> plt.plot(x, z[:, 0], 'ro-', xnew, znew[:, 0], 'b-')
Methods
__call__(x, y[, dx, dy]) | Interpolate the function. |