scipy.interpolate.pchip_interpolate¶
- scipy.interpolate.pchip_interpolate(xi, yi, x, der=0, axis=0)[源代码]¶
方便的pChip插补功能。
xi和yi是用于逼近某个函数f的值的数组,其中
yi = f(xi)
。插值使用单调三次样条来求新点x及其导数的值。看见
scipy.interpolate.PchipInterpolator
有关详细信息,请参阅。- 参数
- xiarray_like
长度为N的x坐标的排序列表。
- yiarray_like
实值的一维数组。 yi 沿插值轴的长度必须等于 xi 。如果是N-D阵列,则使用轴参数选择正确的轴。
- x标量或类似数组
长度为M。
- derint或list,可选
要提取的衍生品。可以包含0阶导数以返回函数值。
- axis整型,可选
与x坐标值对应的yi数组中的轴。
- 退货
- y标量或类似数组
长度为R或长度为M或M乘以R的结果,
参见
PchipInterpolator
PCHIP一维单调三次插值器。
示例
我们可以使用pChip插值对2D观测数据进行插值:
>>> import matplotlib.pyplot as plt >>> from scipy.interpolate import pchip_interpolate >>> x_observed = np.linspace(0.0, 10.0, 11) >>> y_observed = np.sin(x_observed) >>> x = np.linspace(min(x_observed), max(x_observed), num=100) >>> y = pchip_interpolate(x_observed, y_observed, x) >>> plt.plot(x_observed, y_observed, "o", label="observation") >>> plt.plot(x, y, label="pchip interpolation") >>> plt.legend() >>> plt.show()