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()
添加回答
舉報