- 为了满足对函数光滑性的需要,我们可以使用一种有弹性的长条(称之为样条),强迫它弯曲通过样本点。
-
import numpy as np
import matplotlib.pylab as pl
from scipy import interpolate
x = np.linspace(0, 10, 11)
y = np.sin(x)
pl.figure(figsize=(12, 9))
pl.plot(x, y, 'ro')
x_new = np.linspace(0, 10, 101)
for kind in ['nearest', 'zero', 'linear', 'quadratic', 5]: #零阶,零阶,一阶,三阶,五阶
f = interpolate.interp1d(x, y, kind=kind)
y_new = f(x_new)
pl.plot(x_new, y_new, label=str(kind))
pl.xticks(fontsize=20)
pl.yticks(fontsize=20) -
#标签坐落于右下方
pl.legend(loc='lower right')
pl.show() -
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/277288.html