I was trying to plot the wave1-4 of air temperature from 850hPa with contourf and it worked for wave2-4. But the picture of wave1 just showed the positive part and ignored the negative part. The data of wave1 was not wrong cause the method of fft for all wave number is the same.
That’s my code:
t_all = Dataset('t850_all_wave.nc')
t_cli = Dataset('t850_cli_wave.nc')
print(t_all.variables.items())
lat = t_all.variables["latitude"][:]
lon = t_all.variables["longitude"][:]
t_all = t_all.variables["msl"][:]
t_cli = t_cli.variables["msl"][:]
t = np.concatenate((np.array(t_all), np.array(t_cli)))
#%%
fig = plt.figure(figsize=(7,5))
ax_list = []
#???????????
title = ['(a) t850 - wave1','(b) t850 - wave2','(c) t850 - wave3','(d) t850 - wave4']
for i in range(2):
for j in range(2):
ax = fig.add_axes([0.+0.42*j, 0.+0.6*(1-i), 0.5, 0.5],projection = ccrs.NorthPolarStereo(central_longitude=0))
ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False,linewidth=1, color='grey',linestyle='--')
ax.set_boundary(circle, transform=ax.transAxes)
ax.set_extent((-180,180,0,90),ccrs.PlateCarree())
cycle_data, cycle_lon = add_cyclic_point(t[2*i+j], coord=lon)
lv = np.arange(-5,5.1,0.5)
contour1 = ax.contourf(cycle_lon,lat,cycle_data,levels=lv,transform=ccrs.PlateCarree(),cmap=cmaps.BlueWhiteOrangeRed,extend='both')
contour2 = ax.contour(lon,lat,t[2*i+j+4],levels=[-5,-4.5,-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5],colors="black",transform=ccrs.PlateCarree(),linewidths=1.1)
ax.coastlines(lw = 0.5)
plt.title(title[2*i+j],loc="left")
ax_list.append(ax)
position=fig.add_axes([0.92, 0.05, 0.02, 0.95])
cb = plt.colorbar(contour1,ax=ax_list,cax=position,aspect=30,orientation='vertical',label='Wave 1-4 of t850')
plt.savefig("t850.png", dpi=500, bbox_inches='tight')
Once changing the pace of levels from 0.5 to 0.1, it would work and show all the color.I wonder why the levels of contourf would make the color disappear.
potatopotato is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.