<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Arial",sans-serif;
        color:#1F497D;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#1F497D'>Hi,<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#1F497D'>I sent this question to pyngl-talk a while back, please see below. Thought I’d try again. If anyone has any advice that would be great.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#1F497D'>Thank you,<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#1F497D'>Matt<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b>From:</b> pyngl-talk <pyngl-talk-bounces@ucar.edu> <b>On Behalf Of </b>Fearon, Dr. Matthew, Contractor, Code 7533 via pyngl-talk<br><b>Sent:</b> Wednesday, December 4, 2019 11:07 AM<br><b>To:</b> 'pyngl-talk@ucar.edu' <pyngl-talk@ucar.edu><br><b>Subject:</b> [pyngl-talk] contour path coordinates from Ngl.contour<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi,<o:p></o:p></p><p class=MsoNormal>I was wondering if anyone has experience extracting the line path/segment coordinates that define a 2D contour field? I am interested in capturing the coordinates of the closed<span style='color:#1F497D'> or open</span> contour paths and then defining them as polygons.  I have been successful in doing this with matplotlib, shapely, and collections python modules, but I’d prefer the plotting functionality and graphical look of pyngl. And in my experience, having matplotlib and pyngl installed together has always given me problems with dependencies (at least in the anaconda environment). Below is an example of capturing contour path coordinates for a single value of 250 for the 2D variable vflx. I was curious if it is possible to do something similar with Ngl.contour as I do with matplotlib.plt.contour ? I have not figured out a way to pull the x/y coordinates from Ngl.contour that define the contours. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks for the help,<o:p></o:p></p><p class=MsoNormal>Matt<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>        clevels=[250.]<o:p></o:p></p><p class=MsoNormal>        cn = plt.contour(lon2d,lat2d,vflx, levels=clevels)   #is it possible to do this with Ngl.contour ?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>        #loop over the number of contour levels in cn<o:p></o:p></p><p class=MsoNormal>        for i in cn.collections:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>            #loop over all contours per level<o:p></o:p></p><p class=MsoNormal>            for contour_path in i.get_paths():<o:p></o:p></p><p class=MsoNormal>                #each enumerate gives the coordinates that defines the contour exterior<o:p></o:p></p><p class=MsoNormal>                #to_polygons() closes the contour<o:p></o:p></p><p class=MsoNormal>                for ncpts,cpts in enumerate(contour_path.to_polygons()):<o:p></o:p></p><p class=MsoNormal>                    try:<o:p></o:p></p><p class=MsoNormal>                        x = cpts[:,0]<o:p></o:p></p><p class=MsoNormal>                        y = cpts[:,1]<o:p></o:p></p><p class=MsoNormal>                    except:<o:p></o:p></p><p class=MsoNormal>                        x=[]<o:p></o:p></p><p class=MsoNormal>                        y=[]<o:p></o:p></p><p class=MsoNormal>                        for i, (lon,lat) in enumerate(cpts):<o:p></o:p></p><p class=MsoNormal>                            x.append(lon)<o:p></o:p></p><p class=MsoNormal>                            y.append(lat)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                    #create shapely Polygon with x and y<o:p></o:p></p><p class=MsoNormal>                    poly = Polygon([(k[0], k[1]) for k in zip(x,y)])<o:p></o:p></p></div></body></html>