for i in range(16): time = data_sfc['cape'].metpy.time data_crs = data_sfc['cape'].metpy.cartopy_crs fig = plt.figure(1, figsize=(18, 18)) ax = fig.add_subplot(111, projection=ccrs.Mercator()) ax.set_extent([1, 10, 47, 52]) clevs_qv = np.arange(0, 9.5, 0.5) cmap = plt.get_cmap('CMRmap_r') newcmap = ListedColormap(cmap(np.linspace(0, 0.9, 20))) mxcape = ax.contourf(data_sfc.longitude, data_sfc.latitude, ehi3.metpy.loc[{'time': time[i]}], clevs_qv, cmap=newcmap, transform=data_crs) cb = plt.colorbar(mxcape, orientation='vertical', shrink=0.7, aspect=30, pad=0.025) #cb.set_label('kg kg⁻¹', fontsize=18) cb.ax.tick_params(labelsize=16) cb.set_ticks([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) #maxcapes = ax.contour(data_ml.longitude, data_ml.latitude, ehi1.metpy.loc[{'time': time[i]}], #levels=[1, 3, 5, 7, 9], colors='black', linestyles='dotted', linewidths=2, transform=data_crs) #plt.clabel(maxcapes, fmt='%d', fontsize=14) #wind_slice = (slice(None, None, 4), slice(None, None, 4)) #ax.barbs(x[wind_slice[0]], y[wind_slice[1]], #ulls.metpy.loc[{'time': time[i]}].values[wind_slice[0], wind_slice[1]]*1.94384, #vlls.metpy.loc[{'time': time[i]}].values[wind_slice[0], wind_slice[1]]*1.94384, #pivot='tip', color='blue', transform=data_crs, length=8) #wind_slice = (slice(None, None, 4), slice(None, None, 4)) #ax.barbs(x[wind_slice[0]], y[wind_slice[1]], #umls.metpy.loc[{'time': time[i]}].values[wind_slice[0], wind_slice[1]]*1.94384, #vmls.metpy.loc[{'time': time[i]}].values[wind_slice[0], wind_slice[1]]*1.94384, #pivot='tip', color='red', transform=data_crs, length=8) gl = ax.gridlines(draw_labels=True,linewidth=0.5, color='gray', alpha=0.5, linestyle='--') gl.xlabels_top = False gl.ylabels_right = False gl.xlabel_style = {'size': 12, 'color': 'black'} gl.ylabel_style = {'size': 12, 'color': 'black'} gl.xformatter = LONGITUDE_FORMATTER gl.yformatter = LATITUDE_FORMATTER ax.add_feature(cfeature.COASTLINE.with_scale('10m'), LineWidth=3) ax.add_feature(cfeature.BORDERS.with_scale('10m'),LineWidth=3) plt.title('0-3 km EHI\n' + timeinit.strftime('Init: %d.%m.%Y %H:%M UTC ') + time[i].dt.strftime(' Valid: %d.%m.%Y %H:%M UTC').item(), fontsize=18) plt.gcf().text(0.125, 0.18, 'Data: ECMWF HRES', fontsize=12) plt.gcf().text(0.125, 0.20, 'Note: EHI is calculated as follows (CAPE x SRH)/(16 x 10⁴).', fontsize=14) #time2 = time[i].dt.strftime('%Y%m%d%H%M').item() time2 = str(i*3+3) base_filename='ecmwf_ehi_' suffix='.png' latest='latest' my_file = base_filename+time2+suffix print(my_file) plt.savefig(my_file, format="png", bbox_inches='tight', dpi=75) plt.close("all")