from matplotlib.toolkits.basemap import Basemap, NetCDFFile
import pylab, numpy
# read in sea-surface temperature data (over http)
f = NetCDFFile('http://nomads.ncdc.noaa.gov:8085/thredds/dodsC/oisst/2007/AVHRR/sst4-navy-eot.20071129.nc')
lats = f.variables['lat'][:]
lons = f.variables['lon'][:]
sst = f.variables['sst'][:]
# create Basemap instance for mollweide projection.
m = Basemap(projection='moll',lon_0=lons.mean(),resolution=None)
# compute map projection coordinates of grid.
x, y = m(*numpy.meshgrid(lons, lats))
# plot with pcolor or pcolormesh
# works for pcolor
#im = m.pcolor(x, y, sst, cmap=pylab.cm.gist_ncar, shading='flat')
# but not with pcolormesh
im = m.pcolormesh(x, y, sst, cmap=pylab.cm.gist_ncar,shading='flat')
# draw parallels and meridians, but don't bother labelling them.
m.drawparallels(numpy.arange(-90.,91.,30.))
m.drawmeridians(numpy.arange(0.,360.,60.))
# draw line around map projection limb.
m.drawmapboundary(fill_color='k')
pylab.show()
