How To Create A 3D Surface From Given Coordinates With Python?
I have some discrete coordinates with their heights and I need to create a smooth surface which I will continue to use. I need to have heights for all the coordinates in that surfa
Solution 1:
One possibility is to use method griddata
from scipy.
Here is small example how to use neareast neighbour interpolation method with your data:
import numpy as np
from scipy.interpolate import griddata
# --------------------
Z=[]
Z.append([20.2, 20.1, 35])
Z.append([20.1, 24.5, 36])
Z.append([21.0, 23.2, 33])
Z.append([22.3, 20.0, 34])
Z.append([22.3, 19.5, 28])
Z.append([20.1, 19.5, 27])
Z.append([20.1, 24.6, 31])
Z.append([22.3, 24.6, 32])
# ---------------------------
xin=np.array(Z)[:,0];
yin=np.array(Z)[:,1];
zin=np.array(Z)[:,2];
# ----------------------------
xout=np.linspace(20.,23.,10);
yout=np.linspace(19.,25.,10);
xout,yout = np.meshgrid(xout,yout);
# ----------------------------
zout=griddata((xin,yin),zin,(xout,yout),'nearest');
# -----------------------------
from pylab import pcolormesh,show
pcolormesh(xout,yout,zout);show();
Post a Comment for "How To Create A 3D Surface From Given Coordinates With Python?"