Interpolate 2D

from scipy.interpolate import interp2d import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import axes3d def func(x,y): return (x+y)*np.exp(-5*(x**2+y**2)) x,y = np.mgrid[-1:1:15j, -1:1:15j] fvals = func(x, y) f = interp2d(x,y, fvals, kind='cubic') xnew = np.linspace(-1,1,100) ynew = xnew fnew = f(xnew,ynew) fig = plt.figure(1) plt.clf() plt.imshow(fnew, extent=[-1,1,-1,1], cmap=cm.jet) x2,y2 = np.mgrid[-1:1:100j, -1:1:100j] plt.clf() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x2,y2,fnew, cstride=1, rstride=1, cmap=cm.jet)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.