Mauro Cavalcanti wrote:
> Dear ALL,
>
> Good morning! Here am I again with the first (and perhaps simpler)
> part of a potentially long question on plotting gridded data using MPL
> (*and* Basemap).
>
> Most examples I have found of plotting gridded data (using either
> MATLAB or MPL) depict highly sophisticated 3D plots that are much more
> than I can need, which turn to be plotting of data onto a geographic
> (therefore, regular and 2D) grid and displaying the plot over a
> Basemap (usually, but not necessarily, using an Equirectangular
> projection) -- so that I can come up with something like the attached
> figure.
>
> To begin with, here are some general questions:
>
> 1) Can a plot like this one (but not necessarily identical) be done
> with MPL/Basemap from gridded data?
>   

Mauro:  The answer is yes.  It looks like a pcolor plot with missing 
data over the oceans, so you will probably have to use a masked array 
for the data with the ocean values masked.
> 2) For constructing the grid, I have to use the NumPy meshgrid()
> method, as the data are regularly spaced on a geographic grid. For
> example:
>
> import numpy
> import matplotlib.pyplot as plt
>
> coords = numpy.loadtxt('grid.dat')
> lon = coords[:,0]
> lat = coords[:,1]
> dat = coords[:,2]
> X, Y = numpy.meshgrid(lon, lat)
>
> where grid.dat is as follows (very simple dataset, just for
> demonstration purposes):
>
> -61.05 10.4 20
> -79.43 9.15 50
> -70.66 9.53 10
> -63.11 7.91 40
> -63.11 10.55 20
> -81.18 7.51 80
> -56.48 3.1 90
> -60.5 3.93 10
> -81.01 7.66 5
> -67.43 8.93 10
> -65.96 10.31 20
> -78.93 8.38 30
> -72.86 9.83 40
> -68.4 10.61 40
> -72.98 10.61 20
>
> The first two columns correspond to longitude, latitude, and the third
> correspond to the variable to be plotted onto the grid (species
> richness).
>
> The above script reads the data and generates the grid, but then, how
> can I display it on a 2D grid overlaid on a Basemap?
>   
Assuming that this is a regular grid (so that using meshgrid makes 
sense) you can

using pcolor:

m.pcolormesh(x,y,dat)

using contourf:

m.contourf(x,y,dat,clevs)

using imshow:

m.imshow(dat)

There are examples of all three included with basemap.

HTH,

-Jeff
> Well, as I mentioned above, this is the first part of a longer
> question (but I cannot pursue it first before solving these one
> first).
>
> Thanks in advance for any assistance you can provide.
>
> With best regards,
>
>   
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you.  Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>   


-- 
Jeffrey S. Whitaker         Phone : (303)497-6313
NOAA/OAR/CDC  R/PSD1        FAX   : (303)497-6449
325 Broadway                Boulder, CO, USA 80305-3328


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to