混乱的例子效果很好。我想在 3d 中创建数据的 ab spline
data = np.array([[ 41. , 57. , 92. ],[ 39. , 57. , 92.4],[ 43. , 57. , 91.2], [ 23., 47. , 119.6],
[ 27. , 47. , 115.2], [ 25. , 45. , 122. ], [ 25. , 49. , 114. ],[ 29., 49. , 109.6],
[ 29. , 47. , 114.4], [ 27. , 49. , 111.2], [ 23. , 45. , 125.6], [ 31., 49., 106.8],
[ 25. , 47. , 117.6], [ 39. , 55. , 95.6],[ 37. , 53. , 98.4], [ 35. , 55. , 96.8],
[ 33. , 53. , 116.8], [ 23. , 43. , 132.8], [ 25. , 41. , 145.2],[ 25. , 43., 133.6],
[ 29. , 51. , 106.4],[ 31. , 53. , 121.2],[ 31., 51. , 104.8],[ 41., 55., 93.6],
[ 33. , 51. , 103.6],[ 35. , 53. , 99.6],[ 37. , 55. , 96.4]])
x = data[:,0]
y = data[:,1]
z = data[:,2]
# sort data to avoid plotting problems
x, y, z = zip(*sorted(zip(x, y, z)))
x = np.array(x)
y = np.array(y)
z = np.array(z)
import scipy as sp
import scipy.interpolate
from mpl_toolkits.mplot3d import Axes3D
spline = sp.interpolate.Rbf(x,y,z,function='thin_plate',smooth=5, episilon=5)
x_grid = np.linspace(min(x),max(x), len(x))
y_grid = np.linspace(min(y),max(y), len(y))
B1, B2 = np.meshgrid(x_grid, y_grid, indexing='xy')
Z = spline(B1,B2)
fig = plt.figure(figsize=(10,6))
ax = Axes3D(fig)
ax.plot_wireframe(B1, B2, Z)
ax.plot_surface(B1, B2, Z,alpha=0.2)
ax.scatter3D(x,y,z, c='r')
plt.show()