成功解决ImportError: cannot import name 'spline' from 'scipy.interpolate'—利用make_interp_spline函数绘制平滑的曲线
ImportError: cannot import name 'spline' from 'scipy.interpolate'
导入错误:无法从“scipy.interpolate”导入名称“spline”
库版本升级导致函数改变
将
from scipy.interpolate import spline
改为
from scipy.interpolate import make_interp_spline
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import make_interp_spline
x = np.array([6, 8, 10, 12])
y = np.array([35, 7, 2, 1])
x_smooth = np.linspace(x.min(), x.max(), 100)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.plot(x,y,'r')
plt.plot(x_smooth, y_smooth, 'b',linestyle=':')
plt.show()
联系客服