Obtaining the contour data in terms of latitude and longitude

I'm wondering if we could make this easier by modifying contour/contourf so
that the ContourSet object created had a paths object attribute. It
doesn't seem like it'd be that hard. Maybe some would object that it would
slow down the creation of contour plots?

Jon

···

On Wed, Oct 18, 2017 at 5:08 PM, <matplotlib-users-request at python.org> wrote:

Date: Thu, 19 Oct 2017 02:29:11 +0530
From: "ashwin .D" <winash12 at gmail.com>
To: matplotlib-users at python.org
Subject: [Matplotlib-users] Obtaining the contour data in terms of
        latitude and longitude
Message-ID:
        <CAH0LXy4O++PS3morh4B1L-83TvDqRG64YMkDrDe3LKQewFUSiw@
mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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/questions/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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/
attachments/20171019/c5cb0664/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sfc_trough1.gif
Type: image/gif
Size: 13312 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/
attachments/20171019/c5cb0664/attachment-0001.gif>

------------------------------

Message: 2
Date: Wed, 18 Oct 2017 17:08:16 -0400
From: Benjamin Root <ben.v.root at gmail.com>
To: "ashwin .D" <winash12 at gmail.com>
Cc: Matplotlib-users <matplotlib-users at python.org>
Subject: Re: [Matplotlib-users] Obtaining the contour data in terms of
        latitude and longitude
Message-ID:
        <CANNq6FnAWDDv1vahui+WZY=JYwjEcQpiHDQUPxDKhbk-fEb6tQ at mail.
gmail.com>
Content-Type: text/plain; charset="utf-8"

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/
> questions/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/20171018/b9f14b69/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

------------------------------

End of Matplotlib-users Digest, Vol 27, Issue 24
************************************************

--
________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171019/fe2c0cde/attachment-0001.html>

See https://github.com/matplotlib/matplotlib/issues/367 for discussion and
examples of good and bad ways of doing this.
Ian

···

On 19 October 2017 at 13:32, Slavin, Jonathan <jslavin at cfa.harvard.edu> wrote:

I'm wondering if we could make this easier by modifying contour/contourf
so that the ContourSet object created had a paths object attribute. It
doesn't seem like it'd be that hard. Maybe some would object that it would
slow down the creation of contour plots?

Jon

On Wed, Oct 18, 2017 at 5:08 PM, <matplotlib-users-request at python.org> > wrote:

Date: Thu, 19 Oct 2017 02:29:11 +0530
From: "ashwin .D" <winash12 at gmail.com>
To: matplotlib-users at python.org
Subject: [Matplotlib-users] Obtaining the contour data in terms of
        latitude and longitude
Message-ID:
        <CAH0LXy4O++PS3morh4B1L-83TvDqRG64YMkDrDe3LKQewFUSiw at mail.
gmail.com>
Content-Type: text/plain; charset="utf-8"

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/questions/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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachmen
ts/20171019/c5cb0664/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sfc_trough1.gif
Type: image/gif
Size: 13312 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachmen
ts/20171019/c5cb0664/attachment-0001.gif>

------------------------------

Message: 2
Date: Wed, 18 Oct 2017 17:08:16 -0400
From: Benjamin Root <ben.v.root at gmail.com>
To: "ashwin .D" <winash12 at gmail.com>
Cc: Matplotlib-users <matplotlib-users at python.org>
Subject: Re: [Matplotlib-users] Obtaining the contour data in terms of
        latitude and longitude
Message-ID:
        <CANNq6FnAWDDv1vahui+WZY=JYwjEcQpiHDQUPxDKhbk-fEb6tQ at mail.gm
ail.com>
Content-Type: text/plain; charset="utf-8"

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/
> questions/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/attachmen
ts/20171018/b9f14b69/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

------------------------------

End of Matplotlib-users Digest, Vol 27, Issue 24
************************************************

--
________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
________________________________________________________

_______________________________________________
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/72ab305b/attachment.html>