打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
成功解决ImportError: cannot import name ‘spline‘ from ‘scipy.interpolate‘—利用make_interp_spline函数绘制平滑的曲线

成功解决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

利用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()

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用Python实现数据的二维插值
写SCI论文就用SciPy
4
Python数据分析库 Scipy库,科学计算与数据分析的利器!
插值与拟合matlab实现
Matlab中插值函数汇总和使用说明
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服