Forgot to send to the list <sigh>
···
---------- Forwarded message ----------
From: Scott Sinclair <scott.sinclair.za@...287...>
Date: 30 April 2013 13:20
Subject: Re: [Matplotlib-users] Basemap plotting data on projection
To: ChaoYue <chaoyuejoy@...287...>
On 29 April 2013 23:32, ChaoYue <chaoyuejoy@...287...> 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