from scipy.interpolate import spline报错ImportError: cannot import name 'spline'

问题描述

from scipy.interpolate import spline

报错

ImportError: cannot import name 'spline'

解决方案

导入make_interp_spline并进一步调用

from scipy.interpolate import make_interp_spline

x_smooth = np.linspace(x.min(), x.max(), 300)
y_smooth = make_interp_spline(x, y)(x_smooth)

实例

import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import make_interp_spline

x = np.array([6, 7, 8, 9, 10, 11, 12])
y = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
x_smooth = np.linspace(x.min(), x.max(), 300)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.plot(x_smooth, y_smooth)
plt.show()

在这里插入图片描述

参考文献

  1. matplotlib绘制平滑的曲线
  2. Plot smooth line with PyPlot
发布了248 篇原创文章 · 获赞 89 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/lly1122334/article/details/104252039