from scipy.interpolate import spline報錯ImportError: cannot import name ‘spline‘


from scipy.interpolate import spline報錯ImportError: cannot import name ‘spline‘

一、總結

一句話總結:

導入make_interp_spline而不是spline,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)

 

 

二、from scipy.interpolate import spline報錯ImportError: cannot import name ‘spline‘

轉自或參考:from scipy.interpolate import spline報錯ImportError: cannot import name ‘spline‘
https://blog.csdn.net/lly1122334/article/details/104252039

問題描述

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
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM