python插值分析PI曲线的阈值电流

该代码使用Python的numpy、matplotlib和scipy库进行插值分析,针对PI曲线的阈值电流问题。首先读取Excel数据,然后通过interp1d函数实现不同类型的插值(如最近邻、线性、二次、三次),并计算差分以确定电流变化的峰值点,用于识别阈值电流的特征点。
摘要由CSDN通过智能技术生成

python插值分析PI曲线的阈值电流

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from numpy import diff
from scipy.interpolate import interp1d
from torchvision.ops.misc import interpolate
# plt.rcParams['axes.unicode_minus'] = False
# plt.rcParams['font.sans-serif'] = 'SimHei'
data = pd.read_excel(r'C:\Users\asus\Desktop\data.xlsx')
val=data.values
plt.figure(1)
x=val[:,1]
y=val[:,2]
lx=np.max(x)
ly=np.max(y)
arr=np.stack([x,y])
arr=arr.T


# f2=interp1d(x,y, kind='cubic')
x=np.linspace(0.001,0.034,num=27)
# plt.figure()
# plt.plot(x,y,color='red')
# plt.plot(x,f2,color='b')
# plt.show()
# # print(x_pred)

#
# y = [3, 5, 9, 7, 18, 16, 6, 5, 9, 10]
# x = np.linspace(0, 9, num=10)
# x=[0,1,2,3,4,5,6,7,8,9]

# -*-coding:utf-8 -*-


# x = np.linspace(0, 0.034, 27)
# x=[  0.   1.   2.   3.   4.   5.   6.   7.   8.   9.  10.]
xnew = np.linspace(0.001, 0.034, 101)
# plt.plot(x, y, "ro")
cnt=1


col=np.array([(0,0,0),(31/256,119/256,180/256),(1.0,127/256,14/256),(44/256,160/256,44/256),(214/256,39/256,40/256),(148/256,103/256,189/256)])
for kind in ["nearest", "zero", "slinear", "quadratic", "cubic"]:  # 插值方式
    # "nearest","zero"为阶梯插值
    # slinear 线性插值
    # "quadratic","cubic" 为2阶、3阶B样条曲线插值
    plt.figure(figsize=(20, 8))
    plt.subplot(1,3,1)
    plt.title(kind,fontsize=20,weight='bold')

    f = interp1d(x, y, kind=kind)
    # ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order)
    ynew = f(xnew)



    plt.plot(x, y, "ro",markersize=3)
    plt.plot(xnew, ynew, label=str(kind),color=col[cnt])
    plt.subplot(1, 3, 2)
    plt.title('diff1',fontsize=16,fontdict={'style':'italic'})
    test_diff1 = diff(a=ynew, n=1)
    test_diff2 = diff(a=ynew, n=2)

    diff2_max=test_diff2.max()
    print(diff2_max)
    lendiff2=len(test_diff2)
    for i in range(0,lendiff2):
        if test_diff2[i]==diff2_max:
            diff2_max_x=i+1
            break

    plt.plot(xnew[1:],test_diff1)
    plt.subplot(1, 3, 3)
    plt.title('diff2',fontsize=16,fontdict={'style':'italic'})

    plt.plot(xnew[2:],test_diff2,color=(240/256,140/256,60/256))
    plt.plot(xnew[diff2_max_x+1],test_diff2[diff2_max_x-1],'ro',markersize=2)
    plt.plot([xnew[diff2_max_x+1],xnew[diff2_max_x]],[10,-10],'r--')
    plt.plot([0,1], [0,0], 'k--')
    plt.xlim(0.00,0.035)
    plt.ylim(test_diff2.min()+test_diff2.min()/15,test_diff2.max()+test_diff2.max()/15)

    plt.annotate("(%.4f,0)" % xnew[diff2_max_x+1], xy=(xnew[diff2_max_x+1], 0), xytext=(xnew[diff2_max_x+1],-test_diff2.max()/6.7), arrowprops=dict( arrowstyle="->",linewidth=4),fontsize=15)

    # plt.show()
    cnt+=1

    plt.show()


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值