样条插值
"""
演示二维插值。
"""
import numpy as np
from scipy import interpolate
import pylab as plt
import matplotlib as mpl
def func(x, y):
return (x+y)*np.exp(-5.0*(x**2 + y**2))
y,x= np.mgrid[-1:1:25j, -1:1:25j]
fvals = func(x,y)
newfunc = interpolate.interp2d(x, y, fvals, kind='cubic')
xnew = np.linspace(-1,1,200)
ynew = np.linspace(-1,1,200)
fnew = newfunc(xnew, ynew)
plt.figure(figsize=(16, 9))
plt.subplot(121)
im1=plt.imshow(fvals, extent=[-1,1,-1,1], cmap=mpl.cm.hot, interpolation='nearest', origin="lower")
plt.colorbar(im1)
plt.subplot(122)
im2=plt.imshow(fnew, extent=[-1,1,-1,1], cmap=mpl.cm.hot, interpolation='nearest', origin="lower")
plt.colorbar(im2)
plt.show()