欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python樣條插值的實(shí)現(xiàn)代碼

 更新時(shí)間:2018年12月17日 14:49:28   作者:lucindawuyi  
這篇文章主要為大家詳細(xì)介紹了python樣條插值的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python樣條插值的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
 
plt.rcParams['font.sans-serif']=['SimHei'] #用來正常顯示中文標(biāo)簽
plt.rcParams['axes.unicode_minus']=False #用來正常顯示負(fù)號(hào)
 
#導(dǎo)入數(shù)據(jù)
data1=pd.read_csv('data1.csv',encoding='gbk')
 
#數(shù)據(jù)準(zhǔn)備
X=data1.index #定義數(shù)據(jù)點(diǎn)
Y=data1['滬深300'].values #定義數(shù)據(jù)點(diǎn)
x=np.arange(0,len(data1),0.15) #定義觀測(cè)點(diǎn)
 
#進(jìn)行樣條差值
import scipy.interpolate as spi
 
#進(jìn)行一階樣條差值
ipo1=spi.splrep(X,Y,k=1) #源數(shù)據(jù)點(diǎn)導(dǎo)入,生成參數(shù)
iy1=spi.splev(x,ipo1) #根據(jù)觀測(cè)點(diǎn)和樣條參數(shù),生成插值
 
#進(jìn)行三次樣條擬合
ipo3=spi.splrep(X,Y,k=3) #源數(shù)據(jù)點(diǎn)導(dǎo)入,生成參數(shù)
iy3=spi.splev(x,ipo3) #根據(jù)觀測(cè)點(diǎn)和樣條參數(shù),生成插值
 
 
##作圖
fig,(ax1,ax2)=plt.subplots(2,1,figsize=(10,12))
ax1.plot(X,Y,label='滬深300')
ax1.plot(x,iy1,'r.',label='插值點(diǎn)')
ax1.set_ylim(Y.min()-10,Y.max()+10)
ax1.set_ylabel('指數(shù)')
ax1.set_title('線性插值')
ax1.legend()
ax2.plot(X,Y,label='滬深300')
ax2.plot(x,iy3,'b.',label='插值點(diǎn)')
ax2.set_ylim(Y.min()-10,Y.max()+10)
ax2.set_ylabel('指數(shù)')
ax2.set_title('三次樣條插值')
ax2.legend()

基于《Python 與量化投資 從基礎(chǔ)到實(shí)戰(zhàn)》的內(nèi)容練習(xí)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論