1 回答

TA贡献1818条经验 获得超11个赞
为了全面了解为什么会发生这种情况,您必须以更精细的步骤绘制样条曲线,以显示拟合的三次多项式。
import numpy as np
import matplotlib.pyplot as plt
points = [12.036, 12.22, 12.306, 17.019, 18.624, 18.615, 19.098, 19.15]
ipoints = [12.036, 12.22, 12.306, 17.019, 20.0825, 20.5013, 19.5803, 18.624, 18.615, 19.098, 19.15]
plt.plot([1, 2, 3, 4, 8, 9, 10, 11], points, label='real')
plt.plot(range(1, 12), ipoints, label='pandas')
from scipy.interpolate import CubicSpline as CS
cs = CS([1, 2, 3, 4, 8, 9, 10, 11], points)
plt.plot(range(1, 12), cs(range(1, 12)), label='scipy')
x = np.linspace(1, 12, 200)
plt.plot(x, cs(x), label='scipy-fine')
plt.legend()
plt.show()
添加回答
举报