python 中通过插值或 QHull 的散乱数据轮廓

Contour of scattered data via interpolation or QHull in python

我正在尝试根据我的数据在 z = .95 处绘制等高线,但是,我无法按照我的意愿进行插值。我尝试如下使用 griddata

from scipy.interpolate import griddata
N = 1000
xi = np.linspace(min(x), max(y), N)
yi = np.linspace(min(x), max(y), N)
c = griddata((np.array(x),np.array(y)), 
              np.array(z), (xi[None,:],
              yi[:,None]), method='linear')
fig, sys = plt.subplots()

sys.contour(xi, yi, c, levels = [.95],
     colors=('darkred',),linestyles=('solid',),linewidths=(2,))

也如下图所示,我尝试通过在 0.95 处切割 z 轴来使用 qhull。

a = genfromtxt('data.txt')[:,[0,1]] #data where z <= .95
hull = ConvexHull(a)
sys.plot(a[hull.vertices,0], a[hull.vertices,1], color='red', 
          linestyle='--', lw=2.5, zorder=90, label=r"QHUL")

下面我试图说明这两种方法以及它的本质应该是什么样子(它的不同数据只是为了说明目的),但是,由于我的数据在 (1.7, 420) 附近下降,我得到了锯齿形在那个区域的插值中,我什至无法通过单独处理数据片段来修复,而 QHULL 方法只是错过了数据的准确性,因此我无法使用它。有什么方法可以对数据进行插值以获得如下所示的类似曲线吗?

谢谢!

我的数据如下(x,y,z);

1.950e+00   1.500e+02   9.557e-01
1.950e+00   4.800e+02   9.302e-01
1.950e+00   3.100e+02   9.467e-01
1.900e+00   5.500e+02   9.493e-01
1.700e+00   6.000e+02   9.359e-01
1.700e+00   5.500e+02   9.447e-01
8.430e-01   7.800e+02   9.906e-01
1.300e+00   9.000e+02   9.349e-01
1.655e+00   8.132e+02   9.406e-01
1.138e+00   8.453e+02   9.542e-01
1.728e+00   4.895e+02   9.335e-01
1.953e+00   2.254e+02   9.507e-01
1.932e+00   4.706e+01   9.552e-01
1.661e+00   8.081e+02   9.287e-01
1.956e+00   9.931e+00   9.320e-01
1.947e+00   4.457e+01   9.396e-01
1.949e+00   9.769e+01   9.575e-01
1.912e+00   4.441e+02   9.616e-01
1.956e+00   3.739e+01   9.344e-01
1.953e+00   1.042e+02   9.277e-01
1.957e+00   0.000e+00   9.329e-01
1.938e+00   3.455e+01   9.411e-01
1.946e+00   6.045e+01   9.381e-01
1.951e+00   8.227e+01   9.571e-01
1.962e+00   2.500e+01   9.478e-01
1.951e+00   2.778e+01   9.559e-01
1.949e+00   6.736e+01   9.630e-01
1.949e+00   1.097e+02   9.331e-01
1.708e+00   4.998e+02   9.526e-01
1.951e+00   1.250e+02   9.516e-01
1.730e+00   4.642e+02   9.332e-01
1.912e+00   4.780e+02   9.558e-01
1.927e+00   5.145e+02   9.401e-01
1.712e+00   5.203e+02   9.519e-01
1.722e+00   5.470e+02   9.396e-01
1.962e+00   1.117e+02   9.519e-01
1.962e+00   2.195e+01   9.269e-01
1.962e+00   3.366e+01   9.514e-01
1.959e+00   9.610e+01   9.270e-01
1.959e+00   4.537e+01   9.281e-01
1.959e+00   6.488e+01   9.277e-01
1.959e+00   7.659e+01   9.346e-01
1.953e+00   4.537e+01   9.615e-01
1.950e+00   1.820e+02   9.552e-01
1.950e+00   1.702e+02   9.547e-01
1.950e+00   1.415e+01   9.389e-01
1.947e+00   2.639e+02   9.517e-01
1.947e+00   2.015e+02   9.533e-01
1.941e+00   3.029e+02   9.533e-01
1.935e+00   2.873e+02   9.573e-01
1.959e+00   1.415e+01   9.314e-01
1.959e+00   2.439e+00   9.335e-01
1.899e+00   5.137e+02   9.549e-01
1.896e+00   5.371e+02   9.563e-01
1.888e+00   5.839e+02   9.531e-01
1.870e+00   5.917e+02   9.553e-01
1.722e+00   4.746e+02   9.468e-01
1.716e+00   4.278e+02   9.604e-01
1.704e+00   5.644e+02   9.482e-01
1.683e+00   5.800e+02   9.574e-01
1.609e+00   6.854e+02   9.477e-01
1.263e+00   8.766e+02   9.417e-01
1.198e+00   8.532e+02   9.524e-01
1.172e+00   8.532e+02   9.394e-01
1.927e+00   3.807e+02   9.540e-01
1.582e+00   8.424e+02   9.569e-01
1.000e+00   8.415e+02   9.526e-01
8.817e-01   7.985e+02   9.348e-01
1.954e+00   3.139e+00   9.364e-01
1.932e+00   3.583e+02   9.585e-01
1.910e+00   5.018e+02   9.500e-01
1.891e+00   5.628e+02   9.505e-01
1.858e+00   5.987e+02   9.470e-01
1.752e+00   4.874e+02   9.974e-01
1.711e+00   4.803e+02   9.477e-01
1.698e+00   5.341e+02   9.545e-01
1.687e+00   5.628e+02   9.570e-01
1.638e+00   6.596e+02   9.525e-01
1.624e+00   7.996e+02   9.559e-01
1.624e+00   8.211e+02   9.523e-01
1.619e+00   6.632e+02   9.550e-01
1.611e+00   8.283e+02   9.510e-01
1.605e+00   8.354e+02   9.537e-01
1.597e+00   6.776e+02   9.566e-01
1.592e+00   8.426e+02   9.445e-01
1.956e+00   7.908e+01   9.259e-01

原来数据跨度和插值拆分很重要

N = 40
x = linspace(0.5,2.4,N)
y = linspace(0.,1100.,N)

mean_CL = griddata((Mgo,Mn1), mean_CLs, (x[None,:], y[:,None]), method='linear')

sc.contour(x,y,mean_CL,levels = [.95],colors=('darkred',),linestyles=('solid',),linewidths=(2,))

完成任务。但是,不是将数据聚集在一个区域中,而是可能需要跨越整个 x-y 平面,点不需要靠得太近我收集了 25x0.025 的网格并且它工作得很好。