VT 值分布图绘制:使用 Python 分析不同时间节点的 VT 值变化

本代码使用 Python 绘制 VT 值分布图,分析不同时间节点的 VT 值变化趋势。代码展示了如何读取数据、计算统计量、绘制图表,并使用对数坐标轴展示 VT 值分布。

import numpy as np
import matplotlib.pyplot as plt
import os
import math
import time

### step1: 按照每一片画出不同目录(时间节点)的vt 值的分布
path='.\readvt\log\'
#path='.\vt-32Mb-skyworth\'

path1='.\readvt\results\'

dir=[]
abnorm=[]
vrd=6.0
files=os.listdir(path)
for i in files:
    if os.path.isdir(path+i):
        dir.append(i)

print(dir)

slotn=['1']
#files=['#1 2.log', '#3 4.log', '#5 6.log', '#7 8.log', '#9 10.log',]#,'3.log','4.log','5.log','6.log','7.log','8.log','9.log','10.log','11.log','12.log','13.log',
      # '14.log','15.log','16.log','17.log','18.log','19.log','20.log','21.log','22.log','23.log','24.log','25.log',
       #'26.log','27.log','28.log','29.log','30.log','31.log','32.log','33.log','34.log','35.log','36.log','37.log',
      # '38.log','39.log']#,'40.log']#,'41.log','42.log','43.log','44.log','45.log','46.log','47.log','48.log','49.log',
       #'50.log']#,'#101.log']
#files=['1','2','3','4','5','6','7',
files=['1.log','2.log','3.log','4.log','5.log','6.log','7.log','8.log','9.log','10.log','11.log','12.log','13.log','14.log','15.log','16.log','17.log'
       ,'18.log','19.log','20.log','21.log','22.log','23.log','24.log','25.log','26.log','27.log','28.log','29.log','30.log','31.log','32.log','33.log'
       ,'34.log','35.log','36.log','37.log','38.log','39.log','40.log','41.log','42.log','43.log','44.log','45.log','46.log','47.log','48.log','49.log'
       ,'50.log','61.log','62.log','63.log','64.log','65.log','66.log','67.log','68.log','69.log','70.log',
       '71.log','72.log','73.log','74.log','75.log','76.log','77.log','78.log','79.log','80.log',
       '81.log','82.log','83.log','84.log','85.log','86.log','87.log','88.log','89.log','90.log',
       '91.log','92.log','93.log','94.log','95.log','96.log','97.log','98.log','99.log','100.log']


## step2: 按照目录获取最小值并plt

plt.figure(figsize=(16,8),dpi=80)
for k in dir:
    files=os.listdir(path+k)
    # print(files,k)
    vt0_min=[]  ### list store of min vt value of each dir
    slot_name=[]
    vt_value_flt_wo0=[]
    for p in slotn:
        a='zero pattern vth worsest case:'
        for i in files:
            with open(path+k+'\'+i,'r',encoding='gb18030',errors='ignore') as file:
                data=file.readlines()
                for n in data:
                    if a in n:
                        #print(n)
                        vt_value_str=data[data.index(n)][31:-2]
                        #print(vt_value_str)
                        vt_value_flt_wo0.append(vt_value_str)
                        print(vt_value_flt_wo0,len(vt_value_flt_wo0))
                vt0_min=[float(i) for i in vt_value_flt_wo0]
            #slot_name.append(k+'\'+ str(i))
    #min_slot=slot_name[vt0_min.index(min(vt0_min))]
    print(vt0_min)
    x=np.sort(vt0_min)
    y=np.arange(1,len(x)+1)/len(x)
    plt.yticks(np.arange(-0.05,1.05,0.05)) # set yaxis label precision

    plt.semilogy(x,y,marker='.',linestyle=':',label='%s %d pcs min vt=%f'%(k,len(vt0_min),min(vt0_min)))
    plt.annotate(min(vt0_min),(min(vt0_min),1/len(vt0_min)))
#    plt.annotate('Vrd=%s'%vrd,(vrd+0.05,0.5))
    #plt.annotate(vt0_min[int(len(vt0_min)/2)],(vt0_min[int(len(vt0_min)/2)],0.5))#1/int(len(vt0_min)/2)))
    #plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,bottom=0.13, top=0.91)
#    plt.axvline(x=vrd,ls='-',c='red')
    plt.margins(x=0.5, y=0.05)
    plt.xlabel('vt value last not 0 count')
    plt.ylabel('cumulative probability (log10)')
    plt.legend(loc='lower right',fontsize='small')#'best'
    plt.tight_layout()
    plt.grid(b=bool)
    plt.title('vt distribution')
    #plt.show()
t = time.strftime('%Y%m%d-%H%M',time.localtime(time.time()))
plt.tight_layout()
plt.savefig(path1+'min_vt_value_distribution.png')
    #plt.savefig(path2+'vtdistr.png')
plt.close()

代码说明:

  1. 导入库: 导入 numpymatplotlib.pyplotosmathtime 库。
  2. 设置路径: 设置数据路径 path 和结果保存路径 path1
  3. 读取目录: 读取 path 目录下的所有子目录,并存储到 dir 列表中。
  4. 循环遍历目录: 循环遍历 dir 列表中的每个目录。
  5. 读取数据: 读取每个目录下的所有文件,并提取 VT 值数据。
  6. 计算统计量: 计算每个目录下的 VT 值最小值。
  7. 绘制图表: 使用 plt.semilogy() 函数绘制 VT 值分布图,并将 y 轴设置为对数坐标轴。
  8. 保存图表: 将图表保存到 path1 目录下。

修改后的代码将 y 轴设置为对数坐标轴,同时保持 y 值不变。

注意:

  • 确保代码中的路径指向正确的数据和结果目录。
  • 可以根据需要修改图表的大小、标签、颜色等设置。
  • 如果代码中出现错误,请检查代码中的路径、文件名和数据格式。

原文地址: https://www.cveoy.top/t/topic/oDGB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录