Hi,
its been a while but it might help to make Ben's description more specific w.r.t. binning the
data to obtain a z-value array of suitable dimension from irregular data. Starting point
are the following variables:
gmax, gmay: lists (or arrays) of irregular data point coordinates (possibly already in the desired projection)
gmaVal: list of respective z-values.
The following snippet creates a contour line plot with interpolating colours between the contour lines:
SNIPPET:
xi = numpy.linspace(min(gmax),max(gmax),500)
yi = numpy.linspace(min(gmay),max(gmay),500)
zi = griddata(gmax,gmay,gmaVal,xi,yi,interp='nn')
CS = pyplot.contour (xi,yi,zi,15,colors='grey',linewidths=0.1)
CS = pyplot.contourf(xi,yi,zi,15,cmap=cm.get_cmap("jet"))
The number 500 is arbitrary and should suit your desired resolution.
Look up the function "griddata" in:
from matplotlib.mlab import griddata
for which you quickly find descriptions in the web under the key words "irregularly spaced data".
This is a topic in itself.
In most (non-pathologic) cases it probably makes no differerence whether interpolating in projected
coords or in lon-lat.
Regards
Daniel
ยทยทยท
On Thursday, January 20, 2011, Jeff Whitaker <jswhit@...146...> wrote:
On 1/20/11 2:31 PM, R. Mitra wrote:
Hi
? ? ?I have a set of records with known lat long. ?I want to show the
concentration of the records with a contour diagram on a world map in
any projection. It cannot spill over to the oceans. I know I have to
use basemap. ?Is there a quick recipe somewhere I can follow to give
me a desired output. ?I have gone through earlier posts on this board
but cannot find the right one. ?Any pointers would be very helpful.
Many thanks.
Best
MitraMitra: ?The basic procedure is this:
1) load you data into 2d numpy arrays (lats, lons, data). ?lats and lons
must be in degrees (not radians).
2) create a Basemap instance (called "map") for the desired projection.
3) calculate the map projection coordinates of your grid with x,y =
map(lons,lats)
4) contour your data with the contourf method (map.contourf).
5) draw coastlines with the coastlines method.
6) draw lat/lon lines with the drawparallels and drawmeridians methods.There are many examples of this in the basemap examples directory.
-Jeff
In order to contour, you will need some sort z-value to contour. This
means you need to bin your data. You could use numpy's hist2d, or (I
prefer) matplotlib's hexbin().I hope that helps!
Ben Root