In the mpl basemap 'test.py' script, I want to add some contours to the
mercator projection map (test #3).  Just below line 83 (ie, below the 'im  =
imshow..' command I added the line:

m.contour(topodat,[-1000, -2000])

This returns:

/home/evan/downloads/basemap-0.9.4/examples/test.py
    82 # plot image over map.
    83 im = m.imshow(topodat,cm.jet)
---> 84 m.contour(topodat,[-1000, -2000])
    85 m.drawcoastlines()
    86 m.drawcountries()

TypeError: contour() takes at least 4 arguments (3 given)
WARNING: Failure executing file: <test.py>

I understand the error to mean that I haven't supplied x and y values;
however at this point, if I close all the open figures and enter the line
'contour(topodat,[-1000, -2000])' at the ipython command, it gives me the
plot I want.

I've then tried to use meshgrid to make x and y values (see code below);
this is error free but the contours don't appear.  Again, using contour in
the command line I get the plot I want.  Is it not possible to plot on top
of imshow?

Any help appreciated.


Thanks, Evan




from matplotlib.toolkits.basemap import Basemap, shiftgrid
from scipy import interpolate as Pinterp
from pylab import *
import matplotlib.colors as colors

def doSpline(yVec, newLatRange):
   latRange    = range(len(yVec))
   newLatRange = linspace(latRange[0], latRange[-1], newLatRange)
   tck         = Pinterp.splrep(latRange, yVec)
   yVec        = Pinterp.splev(newLatRange, tck)
   return yVec

topodatin = load('etopo20data.gz')
lonsin = load('etopo20lons.gz')
latsin = load('etopo20lats.gz')
# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topodatin,lonsin,start=False)
lats = latsin
# transform to nx x ny regularly spaced native projection grid
nx = len(lons)
ny = int(80.*len(lats)/90.)
lats_ny = doSpline(lats, ny)

lons_mesh, lats_mesh = meshgrid(lons, lats_ny)

# setup mercator map projection (-80 to +80).
m = Basemap(llcrnrlon=-180.,llcrnrlat=-80,urcrnrlon=180.,urcrnrlat=80.,\
           resolution='c',area_thresh=10000.,projection='merc',\
           lon_0=0.5*(lons[0]+lons[-1]),lat_ts=20.)

topodat = m.transform_scalar(topoin,lons,lats,nx,ny)

# setup figure with same aspect ratio as map.
fig=figure()
fig.add_axes([0.1,0.1,0.75,0.75])
# plot image over map.
im = m.imshow(topodat,cm.jet)
# PLOT CONTOURS
m.contour(lons_mesh, lats_mesh, topodat,[-1000, -2000, -3000])
show()
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to