[Matplotlib-users] Obtaining the contour data in terms of latitude and longitude

ashwin .D winash12 at gmail.com
Thu Oct 19 04:48:24 EDT 2017


Hi Ben,
             I believe have a better idea of my doubt  and I am just
thinking loudly here - apologies if all of this is irrelevant. Usually when
you have a raster grid  you need to define it with respect to a origin. So
since in my case I have a global grid the lower left hand corner is taken
to be the origin. This is usually -90 S, 180 W. But you could also have a
subset of the global grid in which case the lower left corner's  latitude
and longitude can be considered as the origin. This is important especially
if you want to know what is grid  orientation of the contour with respect
to the origin. I presume I do not need to worry about this with
matplotlib's contourf  - am I correct on that or put it differently does it
even matter ?

Looking in the code collections.py under lib/matplotlib I see some
references to rasterizing a grid and affine transformations. I am not sure
whether that is related to any of what I just asked.

Best regards,
Ashwin.

On Thu, Oct 19, 2017 at 2:38 AM, Benjamin Root <ben.v.root at gmail.com> wrote:

> If you passed the coordinate arrays in with the call to contourf(), then
> you will get what you expect.
>
> I should note that you should watch out for path simplification (you'll
> want to turn it off). I also recommend using contourf() over contour()
> because it handles the edges of the domain better and NaNs.
>
> Cheers!
> Ben Root
>
>
> On Wed, Oct 18, 2017 at 4:59 PM, ashwin .D <winash12 at gmail.com> wrote:
>
>> Hello,
>>          I have data on a 2d lat lon grid(equal grid spacing) in terms of
>> laitude and longitude and heights as enclosed in the image. I need the
>> coordinates(in terms of latitude and longitude) of the contours( as shown
>> in red in the image). From this answer - https://stackoverflow.com/ques
>> tions/18304722/python-find-contour-lines-from-matplotlib-pyplot-contour/
>> will this give me what I am looking for or is there a scaling required to
>> latitude and longitude that I need to include?
>>
>> Best regards,
>> Ashwin.
>>
>> import numpy as np
>> def get_contour_verts(cn):
>>     contours = []
>>     # for each contour line
>>     for cc in cn.collections:
>>         paths = []
>>         # for each separate section of the contour line
>>         for pp in cc.get_paths():
>>             xy = []
>>             # for each segment of that section
>>             for vv in pp.iter_segments():
>>                 xy.append(vv[0])
>>             paths.append(np.vstack(xy))
>>         contours.append(paths)
>>
>>     return contours
>>
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171019/9a94cf5d/attachment.html>


More information about the Matplotlib-users mailing list