from pykrige import UniversalKriging
import numpy as np
from matplotlib import pyplot as plt, cm
# 要用来拟合的数据
x1 = np.array([0.17, 3.0, 6.49, 8.97, 11.07, 13.38, 15.51])
x2 = np.array([-2.21, -1.61, -0.55, 0.71, 2.61, 3.50, 3.30])
y = np.array([18.76, 15.85, 15.07, 14.47, 16.27, 16.53, 29.64])
# 网格
gridx = np.mgrid[0:16:20j]
gridy = np.mgrid[-3:4:20j]
# kriging模型
uk3d = UniversalKriging(x1, x2, y, variogram_model="gaussian")
# variogram_model是变差函数模型,pykrige提供 linear, power, gaussian, spherical, exponential, hole-effect几种variogram_model可供选择,默认的为linear模型。
# 不太理解这一步的作用
k3d1, ss3d = uk3d.execute("grid", gridx, gridy)
# 输出结果
print(np.round(k3d1, 2))
# 绘图
fig = plt.figure(figsize=(8, 6))
ax1 = fig.add_subplot(111, projection="3d")
ax1.scatter(x1, x2, y, c='r', marker='o')
ax1.plot_surface(gridx, gridy, k3d1, cmap=cm.BuGn_r)
ax1.set_title("ordinary kriging")
ax1.set_xlabel("x")
ax1.set_ylabel("y")
ax1.set_zlabel("z")
plt.tight_layout()
plt.show()
0 Answer
No answer yet
这家伙很懒,什么都没留下...