Dear Phil,

Thank you. This solves my problem. So the title of my mail is wrong, the
behaviour is reasonable but I am using wrong coordinates.
And also thanks to Jeff.

Cheers,

Chao


On Wed, Apr 16, 2014 at 10:14 AM, Phil Elson <pelson....@gmail.com> wrote:

> Hi Chao,
>
> The warning you are getting:
>
> WARNING: x coordinate not monotonically increasing - contour plot
> may not be what you expect.  If it looks odd, your can either
> adjust the map projection region to be consistent with your data, or
> (if your data is on a global lat/lon grid) use the shiftgrid
> function to adjust the data to be consistent with the map projection
> region (see examples/contour_demo.py).
>
> Is important here. It looks like the x coordinate is not in appropriate
> longitudes. Printing the first 5 and last 5 longitudes gives us our first
> clue:
>
> First 5: [-180.         -178.99720764 -177.99443054 -176.99163818 
> -175.98886108]
> Last 5 : [ 175.98886108  176.9916687   177.9944458   178.9972229   
> 180.00003052]
>
> Notice that the last longitude wraps around beyond 180. So if we were to
> clip these numbers to -180 and +180 we will see that the warning disappears
> and the contour is correct. This can be achieved with:
>
> lon = np.clip(lon, -180, 180)
>
> Alternatively, we can just construct the latitudes and longitudes
> ourselves directly with:
>
> lon, lat = np.meshgrid(np.linspace(-180, 180, 360), np.linspace(-90, 90,
> 180))
>
> Incidentally, I tried these numbers with cartopy which has been designed
> to handle dateline wrapping automatically, and the contour worked with the
> unmodified longitudes (http://nbviewer.ipython.org/gist/pelson/10830039).
>
> ---------------------------
>
> @JeffWhitaker - This looks like a bug with float tolerances in the
> makegrid function. It currently does:
>
>     def makegrid(self,nx,ny,returnxy=False):
>         dx = (self.urcrnrx-self.llcrnrx)/(nx-1)
>         dy = (self.urcrnry-self.llcrnry)/(ny-1)
>
> But might be better if it did:
>
>    def makegrid(self,nx,ny,returnxy=False):
>         x = np.linspace(self.llcrnrx, self.urcrnrx, nx)
>         y = np.linspace(self.llcrnry, self.urcrnry, ny)
>
> To avoid the multiplicative floating point drift that is currently being
> seen.
>
> HTH,
>
> Phil
>



-- 
please visit:
http://www.globalcarbonatlas.org/
***********************************************************************************
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
************************************************************************************
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to