lon2 = (int(lons[-1] / delon) + 1) * delon meridians = arange(lon1, lon2, delon) m.drawmeridians(ax, meridians) ax.set_xticks([]) # no ticks ax.set_yticks([]) title('Cylindrical Equidistant') print 'plotting Cylindrical Equidistant example, close plot window to proceed ...' show() m = Basemap(lons[0],-80.,lons[-1],80.,\ resolution='c',area_thresh=10000.,projection='merc',\ lon_0=0.5*(lons[0]+lons[-1]),lat_ts=20.) # define grid (nx x ny regularly spaced native projection grid) nx = len(lons) ny = int(80. * len(lats) / 90.) lonsout, latsout = m.makegrid(nx, ny) topodat = interp(topoin, lons, lats, lonsout, latsout) xsize = rcParams['figure.figsize'][0] fig = figure(figsize=(xsize, m.aspect * xsize)) fig.add_axes([0.1, 0.1, 0.8, 0.8]) im = imshow(topodat, cm.jet, extent=(m.llcrnrx, m.urcrnrx, m.llcrnry, m.urcrnry), origin='lower') ax = gca() # get current axis instance m.drawcoastlines(ax) m.drawcountries(ax) m.drawstates(ax) m.fillcontinents(ax) # draw parallels m.drawparallels(ax, circles)
pylab.subplot(211) ax = pylab.gca() # draw coastlines, state and country boundaries, edge of map. m.drawcoastlines() m.drawstates() m.drawcountries() # draw parallels. delat = 10.0 parallels = pylab.arange(0.,90,delat) m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10) # draw meridians delon = 10. meridians = pylab.arange(180.,360.,delon) m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10) ny = data.shape[0]; nx = data.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid. x, y = m(lons, lats) # compute map proj coordinates. # draw filled contours. clevs = [0,1,2.5,5,7.5,10,15,20,30,40,50,70,100,150,200,250,300,400,500,600,750] cs = m.contourf(x,y,data,clevs,cmap=cm.s3pcpn) # new axis for colorbar. l,b,w,h=ax.get_position() cax = pylab.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes # draw colorbar. pylab.colorbar(cs, cax, format='%g', ticks=clevs, drawedges=False) pylab.axes(ax) # make the original axes current again # plot title pylab.title(plottitle+'- contourf',fontsize=10) pylab.subplot(212) ax = pylab.gca()
from matplotlib.toolkits.basemap import Basemap, interp from pylab import * import cPickle # read in data on lat/lon grid. datadict = cPickle.load(open('500hgt.pickle','rb')) hgt = datadict['data']; lons = datadict['lons']; lats = datadict['lats'] # set up map projection (lambert azimuthal equal area). m = Basemap(-150.,-20.,30.,-20., resolution='c',area_thresh=10000.,projection='laea', lat_0=90.,lon_0=-105.) # interpolate to map projection grid. nx = 101 ny = 101 lonsout, latsout = m.makegrid(nx,ny) # get rid of negative lons. lonsout = where(lonsout < 0., lonsout + 360., lonsout) hgt = interp(hgt,lons,lats,lonsout,latsout) dx = (m.xmax-m.xmin)/(nx-1) dy = (m.ymax-m.ymin)/(ny-1) x = m.xmin+dx*indices((ny,nx))[1,:,:] y = m.ymin+dy*indices((ny,nx))[0,:,:] #m = Basemap(lons[0],lats[0],lons[-1],lats[-1],\ # resolution='c',area_thresh=10000.,projection='cyl') #x, y = meshgrid(lons, lats) fig = figure(figsize=(8,8)) plots = ['contour','pcolor']
ax = pylab.gca() # draw coastlines, state and country boundaries, edge of map. m.drawcoastlines() m.drawstates() m.drawcountries() # draw parallels. delat = 10.0 parallels = pylab.arange(0., 90, delat) m.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10) # draw meridians delon = 10. meridians = pylab.arange(180., 360., delon) m.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10) ny = data.shape[0] nx = data.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid. x, y = m(lons, lats) # compute map proj coordinates. # draw filled contours. clevs = [ 0, 1, 2.5, 5, 7.5, 10, 15, 20, 30, 40, 50, 70, 100, 150, 200, 250, 300, 400, 500, 600, 750 ] cs = m.contourf(x, y, data, clevs, cmap=cm.s3pcpn) # new axis for colorbar. l, b, w, h = ax.get_position() cax = pylab.axes([l + w + 0.025, b, 0.025, h]) # setup colorbar axes # draw colorbar. pylab.colorbar(cs, cax, format='%g', ticks=clevs, drawedges=False) pylab.axes(ax) # make the original axes current again # plot title pylab.title(plottitle + '- contourf', fontsize=10)