Here is the explanation for the preceding code:
- netCDF_temp = Dataset('temperature_annual_1deg.nc') loads the temperature data. It is a netCDF-compliant file, so will need the appropriate utility to read the data, which (dataset) we have already imported in the Getting Ready section of this recipe.
- lon = netCDF_temp.variables['lon'][:] and lat = netCDF_temp.variables['lat'][:] extract longitude and latitude coordinates of the locations for which temperature is being plotted.
- temp = netCDF_temp.variables['t_an'][0,0,:,:] extracts the temperature of the first layer.
- temp_cyc, lon_cyc = add_cyclic_point(temp, coord=lon) adds cyclical points to avoid the vertical white line at zero longitude.
- temp_map = ax.pcolormesh(lon_cyc, ...