插值计算
作者:互联网
# -*-coding:utf-8 -*-
# -*-soc-OCV曲线插值计算 -*-
import numpy as np
from scipy import interpolate
import pylab as pl
import pandas as pd
import xlrd
import xlwings as xw
Filename = input('输入文件名,且在程序同一文件夹下: >> ')
df=pd.read_excel(Filename+'.xlsx',sheet_name=0)
x=df['soc']
y=df['ocv']
print(df)
xnew=np.linspace(0,1,100000)
pl.plot(x,y,"ro")
for kind in ["cubic"]:#插值方式
#"nearest","zero"为阶梯插值
#slinear 线性插值
#"quadratic","cubic" 为2阶、3阶B样条曲线插值
f=interpolate.interp1d(x,y,kind=kind)
# ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order)
ynew=f(xnew)
pl.plot(xnew,ynew,label=str(kind))
pl.legend(loc="lower right")
pl.savefig('SOC-OCV')
df = pd.DataFrame(ynew,xnew)
print(df)
df.to_excel('SOC-OCV.xlsx')
pl.show()
标签:kind,xnew,插值,df,计算,pl,OCV 来源: https://www.cnblogs.com/kamiao/p/14753693.html