如何在for循环中绘制多个图形?

时间:2020-09-13 16:39:53

标签: for-loop plot

我有多个(精确到12个).mat文件,其名称为('CONUS _'+“ {:0> 4d}”。format(year)+'_'+“ {:0> 2d}” .format(month)+'。mat')包含类似的变量。现在,我想加载这些.mat文件,从它们中提取我想要的变量(我想要的变量是xgrid,ygrid和sfvmr),并使用for循环使用xgrid和y grid作为axix对sfvmr进行颜色绘制。我已经写了下面的代码,但它似乎不起作用。谁能帮忙。

先谢谢您

start_year = 2013
start_month = 1
end_year = 2013
end_month = 12

l3_path = os.path.join(l3_dir_2,'OMINO2_2013_01.mat')
mat_info = scipy.io.loadmat(l3_path)
            
for year in range(start_year,end_year+1):
    for month in range(1,13):
        if year == start_year and month < start_month:
            continue
        elif year == end_year and month > end_month:
            continue
            l3_path = os.path.join(l3_dir_2,'CONUS_'+"{:0>4d}".format(year)+'_'+"{:0>2d}".format(month)+'.mat')
            mat_info = scipy.io.loadmat(l3_path)
            sfcvmr=mat_info['sfcvmr'][:,:]
            xgrid=mat_info['xgrid'][:]
            ygrid=mat_info['ygrid'][:]
            plt.figure()
            fig, ax = plt.subplots()
            p=ax.pcolormesh(xgrid,np.transpose(ygrid), sfcvmr(year,month))
            plt.colorbar(p,label=r'NO$_2$ surface vmr [ppb]')
            plt.savefig('CONUS_'+"{:0>4d}".format(year)+'_'+"{:0>2d}".format(month)+'.png',dpi=200)'''
            

0 个答案:

没有答案