2024.4.4 データの補間【scipy】
scipy.interpolateを利用する。
一時補間
code:ip_1d01.py
import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 7)
y = np.sin(x)
# いずれか一つを選択する
func = interpolate.interp1d(x,y) # 線形補間
# func = interpolate.interp1d(x,y, kind="nearest") # 最近傍点補間
# func = interpolate.lagrange(x,y) # ラグランジュ補間
# func = interpolate.interp1d(x,y, kind="quadratic") # 2次スプライン補間
# func = interpolate.interp1d(x,y, kind="cubic") # 3次スプライン補間
x_new = np.arange(0, 10, 0.1)
y_new = func(x_new)
plt.plot(x,y, '*')
plt.plot(x_new, y_new, 'x-')
plt.grid()
plt.show()