Dear all,
when trying to contourf data from a netCDF file in North-Polar
Stereographic projection, I encounter the problem that the map is not
filled completely but there is a gap between 0E and some -2E where the
map stays blank (see attached plot).
I am reading the grid (lon,lat) from the respective netCDF file
variables. When plotting with other software, e.g. Ferret or Panoply,
the problem does not occur. The essential code:
import numpy as np
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import matplotlib.spines
# what to plot
anom='Arctic07-Clim'
var='slp'
varclevs={ # contour levels for the given variable
'slp': np.arange(-200,101,25),
'temp2': np.arange(-3,3.5,.5)}
varlabel={ # variable labels
'slp': 'sea level pressure anomaly [Pa]',
'temp2': '2m air temperature anomaly [K]'}
varcmap={ # color map to use for variable
'slp': plt.cm.RdYlBu_r,
'temp2': plt.cm.Spectral}
# paths
dataDir = '...'
plotDir = '...'
# Open file and read data
fname = dataDir + anom+'_ensmean.JASmean.'+var+'.nc'
ncf = Dataset(fname)
vardata = ncf.variables[var][:]
lons = ncf.variables['lon'][:]
lats = ncf.variables['lat'][:]
ncf.close()
# Map projection
m = Basemap(projection='npstere',boundinglat=60,lon_0=-30,resolution='l')
# make coordinate grid for contour plot
xx,yy = m(*np.meshgrid(lons,lats))
# Plot stuff
# set plot
f = plt.figure()
ax = plt.gca()
# draw coast lines etc
m.drawcoastlines(zorder=7)
#m.fillcontinents(zorder=7)
# draw parallels and meridians.
m.drawparallels(np.arange(50,81,10),zorder=8)
m.drawmeridians(np.arange(-30,330,30),zorder=8,latmax=80)
m.drawmeridians(np.arange(-30,330,90),zorder=8,latmax=40,labels=[1,0,1,1])
# label parallels manually
latvals=np.array([70,80])
lonvals=np.ones(len(latvals))*(-15)
for l in range(len(latvals)):
latval = latvals[l]
lonval = lonvals[l]
x,y = m(lonval,latval)
latlab = '{0} N'.format(latval)
ax.text(x,y,latlab,zorder=10,va='center')
# plt.xlabel('longitude')
# plt.ylabel('latitude')
# Contour data
datacntr = m.contourf(xx,yy,vardata[0,:,:],
levels=varclevs[var],
cmap=varcmap[var],
extend='both',zorder=5)
# draw color bar
datacb = plt.colorbar(datacntr,orientation='vertical',shrink=1.)
datacb.set_label(varlabel[var])
I am using the Entought Python Distribution 7.0 on Mac OS X 10.5.
Thanks for your kind help!
Jonas B., GFI, Bergen, Norway
npstere_contourf_problem.pdf (252 KB)