Forgot to send to the list <sigh>
---------- Forwarded message ---------- From: Scott Sinclair <scott.sinclair...@gmail.com> Date: 30 April 2013 13:20 Subject: Re: [Matplotlib-users] Basemap plotting data on projection To: ChaoYue <chaoyue...@gmail.com> On 29 April 2013 23:32, ChaoYue <chaoyue...@gmail.com> wrote: > pdata = np.genfromtxt('pdata.txt') > pdata = np.ma.masked_greater(pdata,1E20) > lonm,latm=m.makegrid(pdata.shape[1],pdata.shape[0]) The problem is here ^^^ The data don't lie on an equally spaced grid in the Mercator projection, so it doesn't make sense to ask for the lat/lon coordinates of a grid that is equally spaced in this projection. You need to determine the *actual* lat/lon coordinates before projecting them onto the Mercator map and plotting... Something like this should work (If you can assume that the data are on an equally spaced grid in Equidistant Cyl projection having the boundaries specified): from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt # Set up the Equidistant Cyl projection to determine data locations. pdata = np.genfromtxt('pdata.txt') pdata = np.ma.masked_greater(pdata, 1E20) ny, nx = pdata.shape cyl_basemap = Basemap(projection='cyl', llcrnrlat=9, urcrnrlat=54.5, llcrnrlon=74, urcrnrlon=142, lat_ts=20, resolution='l') lon, lat = cyl_basemap.makegrid(nx, ny) # Set up the Mercator projection for plotting. m = Basemap(projection='merc', llcrnrlat=9, urcrnrlat=54.5,\ llcrnrlon=74, urcrnrlon=142, lat_ts=20, resolution='l') m.drawcountries() m.drawcoastlines() m.drawmapboundary(fill_color='white') m.drawrivers() x, y = m(lon, np.flipud(lat)) cs = m.contourf(x, y, pdata) m.colorbar(cs) plt.show() Cheers, Scott ------------------------------------------------------------------------------ Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET Get 100% visibility into your production application - at no cost. Code-level diagnostics for performance bottlenecks with <2% overhead Download for free and get started troubleshooting in minutes. http://p.sf.net/sfu/appdyn_d2d_ap1 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users