Tim Michelsen wrote:
> Dear Matplotlib-Users,
> I am tryring to create a contour plot over a basemap.
>
> My main problem is creating the array for the Z values as a basis for the
> plt.contour command from a CSV file where latitude, longitude and value are
> stored column-wise:
>
> lat;  lon;    value
> 50;   10;     6
> ...
>
> The data represents a regular spaced grid with a datapoint each 0.25 degrees.
>
> I tried various possibilities but didn't have success:
>
> 1) following simpletest.py from the basemap examples:
> X, Y = meshgrid(data[:,1], data[:,0])
>
> Z = data[:,2]
>   
Timmie:  Try:

X, Y = meshgrid(data[:,1], data[:,0])
Z = data[:,2]
nlons = X.shape[1]; nlats = X.shape[0]
Z = Z.reshape(nlats,nlons)

> m.contourf(x,y, Z)
>
> => Error: Z must be a 2D array
> -> How do I get Z to be a 2D array?
>
> 2) using the griddata package
> Here I was nearly without orientation how to call griddata correctly.
>   
You don't need to use griddata since you have regularly gridded data.
>
> 3) Using the python bindings of ogr
> Any examples on this one?
>   
Again, no need.  A simple reshape will get you the 2d lat/lon array you 
need.

> >From my above demonstrated methods the following questions arrise:
> What is the preferred way to plot
>       - Points stored in the above descripbed format (lat, lon, value)?
>       - Interpolate a grid of data points by using different interpolation 
> methods
> like inverse distance wheighting, natural neighbor  interpolation, etc. to 
> get a
> contour map?
>   

For interpolation of irregular, randomly distributed data points see
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data.

However, if there is some structure to the data grid then it's probably 
better not to use these approaches.

-Jeff



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


-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to