SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Eli B. <eb...@gm...> - 2009年01月27日 22:52:43
Hello,
I am trying to extract the coordinates of contour lines.
I tried the following:
cs = *contour*(Z)
for lev, col in zip(cs.levels, cs.collections):
 s = col._segments
that I found in a previous post (title "contouring", by Jose
Gómez-Dans-2<http://www.nabble.com/user/UserProfile.jtp?user=30071>
Nov
30, 2007; 07:47am ) .
I hoped that s will be a list of numpy arrays, each containing the (x,y)
vertices
defining a contour line at level lev.
However, I got an error message:
AttributeError: 'LineCollection' object has no attribute '_segments'
How is it possible to get coordinates of the contours, similar to the MATLAB
command
 [C,H] = *CONTOUR*(...)
where the result in C is the coordinates of the contours.
A similar question appeared in a post "contour data" (by Albert
Swart<http://www.nabble.com/user/UserProfile.jtp?user=382945> May
17, 2006; 09:42am) but I could not understand the answer.
Is it possible to get more specific directions with a simple example ?
Thanks
Eli
From: Jeff W. <js...@fa...> - 2009年01月27日 23:33:56
Eli Brosh wrote:
> Hello,
> I am trying to extract the coordinates of contour lines.
> I tried the following:
>
> cs = *contour*(Z)
> for lev, col in zip(cs.levels, cs.collections):
> s = col._segments
>
> that I found in a previous post (title "contouring", by Jose 
> Gómez-Dans-2 <http://www.nabble.com/user/UserProfile.jtp?user=30071> 
> Nov 30, 2007; 07:47am ) .
>
> I hoped that s will be a list of numpy arrays, each containing the 
> (x,y) vertices
> defining a contour line at level lev.
> However, I got an error message:
> AttributeError: 'LineCollection' object has no attribute '_segments'
>
>
> How is it possible to get coordinates of the contours, similar to the 
> MATLAB command
> [C,H] = *CONTOUR*(...)
> where the result in C is the coordinates of the contours.
>
> A similar question appeared in a post "contour data" (by Albert Swart 
> <http://www.nabble.com/user/UserProfile.jtp?user=382945> May 17, 2006; 
> 09:42am) but I could not understand the answer.
> Is it possible to get more specific directions with a simple example ?
>
>
> Thanks
> Eli
Eli: Calling get_paths() on each line collection in CS.collections will 
return a list of Path objects. From the Path objects, you can get a Nx2 
array of vertices from the "vertices" attribute. There are no examples 
that I know of, but if you get it to do what you want to do, it would be 
great if you could contribute an example. As you noted, this question 
has come up several times before.
-Jeff
-- 
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
From: Patrick M. <pat...@gm...> - 2009年01月28日 00:09:27
On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker <js...@fa...> wrote:
> Eli Brosh wrote:
>> Hello,
>> I am trying to extract the coordinates of contour lines.
>> I tried the following:
>>
>> cs = *contour*(Z)
>> for lev, col in zip(cs.levels, cs.collections):
>> s = col._segments
>>
>> that I found in a previous post (title "contouring", by Jose
>> Gómez-Dans-2 <http://www.nabble.com/user/UserProfile.jtp?user=30071>
>> Nov 30, 2007; 07:47am ) .
>>
>> I hoped that s will be a list of numpy arrays, each containing the
>> (x,y) vertices
>> defining a contour line at level lev.
>> However, I got an error message:
>> AttributeError: 'LineCollection' object has no attribute '_segments'
>>
>>
>> How is it possible to get coordinates of the contours, similar to the
>> MATLAB command
>> [C,H] = *CONTOUR*(...)
>> where the result in C is the coordinates of the contours.
>>
>> A similar question appeared in a post "contour data" (by Albert Swart
>> <http://www.nabble.com/user/UserProfile.jtp?user=382945> May 17, 2006;
>> 09:42am) but I could not understand the answer.
>> Is it possible to get more specific directions with a simple example ?
>>
>>
>> Thanks
>> Eli
> Eli: Calling get_paths() on each line collection in CS.collections will
> return a list of Path objects. From the Path objects, you can get a Nx2
> array of vertices from the "vertices" attribute. There are no examples
> that I know of, but if you get it to do what you want to do, it would be
> great if you could contribute an example. As you noted, this question
> has come up several times before.
>
> -Jeff
>
> --
> Jeffrey S. Whitaker Phone : (303)497-6313
> Meteorologist FAX : (303)497-6449
> NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
> 325 Broadway Office : Skaggs Research Cntr 1D-113
> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
I'm not sure if this is entirely what you (Eli) are looking for, but I
have code that will contour model data on a map and then extract the
lat,lon pairs of all the vertices. If this is what you are looking
for, I'm happy to share what I've done.
-Patrick
-- 
Patrick Marsh
Graduate Research Assistant
School of Meteorology
University of Oklahoma
http://www.patricktmarsh.com
From: Eli B. <eb...@gm...> - 2009年01月28日 01:16:11
Many thanks to Jeff and to Patric !
I will try to work along the line suggested by Jeff.
Patric, please send me your code.
I hope to learn from it.
Thanks again,
Eli
On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh <pat...@gm...>wrote:
> On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker <js...@fa...> wrote:
> > Eli Brosh wrote:
> >> Hello,
> >> I am trying to extract the coordinates of contour lines.
> >> I tried the following:
> >>
> >> cs = *contour*(Z)
> >> for lev, col in zip(cs.levels, cs.collections):
> >> s = col._segments
> >>
> >> that I found in a previous post (title "contouring", by Jose
> >> Gómez-Dans-2 <http://www.nabble.com/user/UserProfile.jtp?user=30071>
> >> Nov 30, 2007; 07:47am ) .
> >>
> >> I hoped that s will be a list of numpy arrays, each containing the
> >> (x,y) vertices
> >> defining a contour line at level lev.
> >> However, I got an error message:
> >> AttributeError: 'LineCollection' object has no attribute '_segments'
> >>
> >>
> >> How is it possible to get coordinates of the contours, similar to the
> >> MATLAB command
> >> [C,H] = *CONTOUR*(...)
> >> where the result in C is the coordinates of the contours.
> >>
> >> A similar question appeared in a post "contour data" (by Albert Swart
> >> <http://www.nabble.com/user/UserProfile.jtp?user=382945> May 17, 2006;
> >> 09:42am) but I could not understand the answer.
> >> Is it possible to get more specific directions with a simple example ?
> >>
> >>
> >> Thanks
> >> Eli
> > Eli: Calling get_paths() on each line collection in CS.collections will
> > return a list of Path objects. From the Path objects, you can get a Nx2
> > array of vertices from the "vertices" attribute. There are no examples
> > that I know of, but if you get it to do what you want to do, it would be
> > great if you could contribute an example. As you noted, this question
> > has come up several times before.
> >
> > -Jeff
> >
> > --
> > Jeffrey S. Whitaker Phone : (303)497-6313
> > Meteorologist FAX : (303)497-6449
> > NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
> > 325 Broadway Office : Skaggs Research Cntr 1D-113
> > Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > This SF.net email is sponsored by:
> > SourcForge Community
> > SourceForge wants to tell your story.
> > http://p.sf.net/sfu/sf-spreadtheword
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
> I'm not sure if this is entirely what you (Eli) are looking for, but I
> have code that will contour model data on a map and then extract the
> lat,lon pairs of all the vertices. If this is what you are looking
> for, I'm happy to share what I've done.
>
> -Patrick
>
> --
> Patrick Marsh
> Graduate Research Assistant
> School of Meteorology
> University of Oklahoma
> http://www.patricktmarsh.com
>
From: Patrick M. <pat...@gm...> - 2009年01月28日 04:09:09
On Tue, Jan 27, 2009 at 7:16 PM, Eli Brosh <eb...@gm...> wrote:
> Many thanks to Jeff and to Patric !
> I will try to work along the line suggested by Jeff.
> Patric, please send me your code.
> I hope to learn from it.
>
> Thanks again,
> Eli
Here is a template that can be used. I use this for meteorological
models, but should work with any gridded file.
import numpy as np
from mpl_toolkits.basemap import Basemap
f = (some gridded file)
X = np.array(grab longitudes from f)
Y = np.array(grab latitudes from f)
field = np.array(grab field to be contoured from f)
map = Basemap(make a Basemap call here)
level = np.arange(minval, maxval, interval)
col = map.contour(X, Y, field, level).collections
for vertex in col[i].get_paths(): # GET THE PATHS FOR THE EACH
CONTOUR BY LOOPING THROUGH CONTOURS
 for vertex in xy.vertices: # ITERATE OVER THE PATH OBJECTS
 x, y = map(vertex[0],vertex[1],inverse=True) # vertex[0]
and now 'x' is the longitude of the vertex and vertex[1] and now 'y'
is the latitude of the vertex
Let me know how this works.
-Patrick
>
> On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh <pat...@gm...>
> wrote:
>>
>> On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker <js...@fa...> wrote:
>> > Eli Brosh wrote:
>> >> Hello,
>> >> I am trying to extract the coordinates of contour lines.
>> >> I tried the following:
>> >>
>> >> cs = *contour*(Z)
>> >> for lev, col in zip(cs.levels, cs.collections):
>> >> s = col._segments
>> >>
>> >> that I found in a previous post (title "contouring", by Jose
>> >> Gómez-Dans-2 <http://www.nabble.com/user/UserProfile.jtp?user=30071>
>> >> Nov 30, 2007; 07:47am ) .
>> >>
>> >> I hoped that s will be a list of numpy arrays, each containing the
>> >> (x,y) vertices
>> >> defining a contour line at level lev.
>> >> However, I got an error message:
>> >> AttributeError: 'LineCollection' object has no attribute '_segments'
>> >>
>> >>
>> >> How is it possible to get coordinates of the contours, similar to the
>> >> MATLAB command
>> >> [C,H] = *CONTOUR*(...)
>> >> where the result in C is the coordinates of the contours.
>> >>
>> >> A similar question appeared in a post "contour data" (by Albert Swart
>> >> <http://www.nabble.com/user/UserProfile.jtp?user=382945> May 17, 2006;
>> >> 09:42am) but I could not understand the answer.
>> >> Is it possible to get more specific directions with a simple example ?
>> >>
>> >>
>> >> Thanks
>> >> Eli
>> > Eli: Calling get_paths() on each line collection in CS.collections will
>> > return a list of Path objects. From the Path objects, you can get a Nx2
>> > array of vertices from the "vertices" attribute. There are no examples
>> > that I know of, but if you get it to do what you want to do, it would be
>> > great if you could contribute an example. As you noted, this question
>> > has come up several times before.
>> >
>> > -Jeff
>> >
>> > --
>> > Jeffrey S. Whitaker Phone : (303)497-6313
>> > Meteorologist FAX : (303)497-6449
>> > NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
>> > 325 Broadway Office : Skaggs Research Cntr 1D-113
>> > Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
>> >
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > This SF.net email is sponsored by:
>> > SourcForge Community
>> > SourceForge wants to tell your story.
>> > http://p.sf.net/sfu/sf-spreadtheword
>> > _______________________________________________
>> > Matplotlib-users mailing list
>> > Mat...@li...
>> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> >
>>
>> I'm not sure if this is entirely what you (Eli) are looking for, but I
>> have code that will contour model data on a map and then extract the
>> lat,lon pairs of all the vertices. If this is what you are looking
>> for, I'm happy to share what I've done.
>>
>> -Patrick
>>
>> --
>> Patrick Marsh
>> Graduate Research Assistant
>> School of Meteorology
>> University of Oklahoma
>> http://www.patricktmarsh.com
>
>
-- 
Patrick Marsh
Graduate Research Assistant
School of Meteorology
University of Oklahoma
http://www.patricktmarsh.com
From: Eli B. <eb...@gm...> - 2009年01月30日 15:22:21
Hello again,
I finally found the command I was looking for. It is the to_polygons().
Here is what worked :
# make a LineCollection of contours
col=contour(X,Y,Z,LevelsNumber).collections
for i in np.arange(0,LevelsNumber,1):
 polygoni=col[i].get_paths()[0].to_polygons()[0]
 print polygoni
All the vertices in each collections are extracted to the "polygoni".
Thanks again to Jeff and Patrick !
By the way, I found out that I do not actually need this procedure to
achieve may goal
which was to make a contour plot in ternary coordinates.
Eli
On Tue, Jan 27, 2009 at 11:08 PM, Patrick Marsh <pat...@gm...>wrote:
> On Tue, Jan 27, 2009 at 7:16 PM, Eli Brosh <eb...@gm...> wrote:
> > Many thanks to Jeff and to Patric !
> > I will try to work along the line suggested by Jeff.
> > Patric, please send me your code.
> > I hope to learn from it.
> >
> > Thanks again,
> > Eli
>
>
> Here is a template that can be used. I use this for meteorological
> models, but should work with any gridded file.
>
>
> import numpy as np
> from mpl_toolkits.basemap import Basemap
>
> f = (some gridded file)
> X = np.array(grab longitudes from f)
> Y = np.array(grab latitudes from f)
> field = np.array(grab field to be contoured from f)
> map = Basemap(make a Basemap call here)
> level = np.arange(minval, maxval, interval)
> col = map.contour(X, Y, field, level).collections
>
> for vertex in col[i].get_paths(): # GET THE PATHS FOR THE EACH
> CONTOUR BY LOOPING THROUGH CONTOURS
> for vertex in xy.vertices: # ITERATE OVER THE PATH OBJECTS
> x, y = map(vertex[0],vertex[1],inverse=True) # vertex[0]
> and now 'x' is the longitude of the vertex and vertex[1] and now 'y'
> is the latitude of the vertex
>
>
> Let me know how this works.
>
> -Patrick
>
>
>
>
>
>
>
>
>
> >
> > On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh <pat...@gm...
> >
> > wrote:
> >>
> >> On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker <js...@fa...>
> wrote:
> >> > Eli Brosh wrote:
> >> >> Hello,
> >> >> I am trying to extract the coordinates of contour lines.
> >> >> I tried the following:
> >> >>
> >> >> cs = *contour*(Z)
> >> >> for lev, col in zip(cs.levels, cs.collections):
> >> >> s = col._segments
> >> >>
> >> >> that I found in a previous post (title "contouring", by Jose
> >> >> Gómez-Dans-2 <http://www.nabble.com/user/UserProfile.jtp?user=30071>
> >> >> Nov 30, 2007; 07:47am ) .
> >> >>
> >> >> I hoped that s will be a list of numpy arrays, each containing the
> >> >> (x,y) vertices
> >> >> defining a contour line at level lev.
> >> >> However, I got an error message:
> >> >> AttributeError: 'LineCollection' object has no attribute '_segments'
> >> >>
> >> >>
> >> >> How is it possible to get coordinates of the contours, similar to the
> >> >> MATLAB command
> >> >> [C,H] = *CONTOUR*(...)
> >> >> where the result in C is the coordinates of the contours.
> >> >>
> >> >> A similar question appeared in a post "contour data" (by Albert Swart
> >> >> <http://www.nabble.com/user/UserProfile.jtp?user=382945> May 17,
> 2006;
> >> >> 09:42am) but I could not understand the answer.
> >> >> Is it possible to get more specific directions with a simple example
> ?
> >> >>
> >> >>
> >> >> Thanks
> >> >> Eli
> >> > Eli: Calling get_paths() on each line collection in CS.collections
> will
> >> > return a list of Path objects. From the Path objects, you can get a
> Nx2
> >> > array of vertices from the "vertices" attribute. There are no
> examples
> >> > that I know of, but if you get it to do what you want to do, it would
> be
> >> > great if you could contribute an example. As you noted, this question
> >> > has come up several times before.
> >> >
> >> > -Jeff
> >> >
> >> > --
> >> > Jeffrey S. Whitaker Phone : (303)497-6313
> >> > Meteorologist FAX : (303)497-6449
> >> > NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
> >> > 325 Broadway Office : Skaggs Research Cntr 1D-113
> >> > Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
> >> >
> >> >
> >> >
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> > This SF.net email is sponsored by:
> >> > SourcForge Community
> >> > SourceForge wants to tell your story.
> >> > http://p.sf.net/sfu/sf-spreadtheword
> >> > _______________________________________________
> >> > Matplotlib-users mailing list
> >> > Mat...@li...
> >> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >> >
> >>
> >> I'm not sure if this is entirely what you (Eli) are looking for, but I
> >> have code that will contour model data on a map and then extract the
> >> lat,lon pairs of all the vertices. If this is what you are looking
> >> for, I'm happy to share what I've done.
> >>
> >> -Patrick
> >>
> >> --
> >> Patrick Marsh
> >> Graduate Research Assistant
> >> School of Meteorology
> >> University of Oklahoma
> >> http://www.patricktmarsh.com
> >
> >
>
>
>
> --
> Patrick Marsh
> Graduate Research Assistant
> School of Meteorology
> University of Oklahoma
> http://www.patricktmarsh.com
>
From: Lionel R. <lro...@li...> - 2009年02月02日 08:26:11
Hi all,
just a little question : how matplotlib computes contours? Is it based
on an internal library? Is it possible to access it from outside?
Thanks
Le vendredi 30 janvier 2009 à 10:22 -0500, Eli Brosh a écrit :
> Hello again,
> I finally found the command I was looking for. It is the
> to_polygons().
> Here is what worked :
> 
> # make a LineCollection of contours
> col=contour(X,Y,Z,LevelsNumber).collections
> 
> 
> for i in np.arange(0,LevelsNumber,1):
> polygoni=col[i].get_paths()[0].to_polygons()[0]
> print polygoni
> 
> All the vertices in each collections are extracted to the "polygoni".
> 
> Thanks again to Jeff and Patrick !
> 
> By the way, I found out that I do not actually need this procedure to
> achieve may goal 
> which was to make a contour plot in ternary coordinates.
> 
> Eli
> 
> 
> 
> On Tue, Jan 27, 2009 at 11:08 PM, Patrick Marsh
> <pat...@gm...> wrote:
> On Tue, Jan 27, 2009 at 7:16 PM, Eli Brosh <eb...@gm...>
> wrote:
> > Many thanks to Jeff and to Patric !
> > I will try to work along the line suggested by Jeff.
> > Patric, please send me your code.
> > I hope to learn from it.
> >
> > Thanks again,
> > Eli
> 
> 
> 
> Here is a template that can be used. I use this for
> meteorological
> models, but should work with any gridded file.
> 
> 
> import numpy as np
> from mpl_toolkits.basemap import Basemap
> 
> f = (some gridded file)
> X = np.array(grab longitudes from f)
> Y = np.array(grab latitudes from f)
> field = np.array(grab field to be contoured from f)
> map = Basemap(make a Basemap call here)
> level = np.arange(minval, maxval, interval)
> col = map.contour(X, Y, field, level).collections
> 
> for vertex in col[i].get_paths(): # GET THE PATHS FOR THE
> EACH
> CONTOUR BY LOOPING THROUGH CONTOURS
> for vertex in xy.vertices: # ITERATE OVER THE PATH
> OBJECTS
> x, y = map(vertex[0],vertex[1],inverse=True) #
> vertex[0]
> and now 'x' is the longitude of the vertex and vertex[1] and
> now 'y'
> is the latitude of the vertex
> 
> 
> Let me know how this works.
> 
> -Patrick
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> >
> > On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh
> <pat...@gm...>
> > wrote:
> >>
> >> On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker
> <js...@fa...> wrote:
> >> > Eli Brosh wrote:
> >> >> Hello,
> >> >> I am trying to extract the coordinates of contour lines.
> >> >> I tried the following:
> >> >>
> >> >> cs = *contour*(Z)
> >> >> for lev, col in zip(cs.levels, cs.collections):
> >> >> s = col._segments
> >> >>
> >> >> that I found in a previous post (title "contouring", by
> Jose
> >> >> Gómez-Dans-2
> <http://www.nabble.com/user/UserProfile.jtp?user=30071>
> >> >> Nov 30, 2007; 07:47am ) .
> >> >>
> >> >> I hoped that s will be a list of numpy arrays, each
> containing the
> >> >> (x,y) vertices
> >> >> defining a contour line at level lev.
> >> >> However, I got an error message:
> >> >> AttributeError: 'LineCollection' object has no attribute
> '_segments'
> >> >>
> >> >>
> >> >> How is it possible to get coordinates of the contours,
> similar to the
> >> >> MATLAB command
> >> >> [C,H] = *CONTOUR*(...)
> >> >> where the result in C is the coordinates of the
> contours.
> >> >>
> >> >> A similar question appeared in a post "contour data" (by
> Albert Swart
> >> >> <http://www.nabble.com/user/UserProfile.jtp?user=382945>
> May 17, 2006;
> >> >> 09:42am) but I could not understand the answer.
> >> >> Is it possible to get more specific directions with a
> simple example ?
> >> >>
> >> >>
> >> >> Thanks
> >> >> Eli
> >> > Eli: Calling get_paths() on each line collection in
> CS.collections will
> >> > return a list of Path objects. From the Path objects,
> you can get a Nx2
> >> > array of vertices from the "vertices" attribute. There
> are no examples
> >> > that I know of, but if you get it to do what you want to
> do, it would be
> >> > great if you could contribute an example. As you noted,
> this question
> >> > has come up several times before.
> >> >
> >> > -Jeff
> >> >
> >> > --
> >> > Jeffrey S. Whitaker Phone : (303)497-6313
> >> > Meteorologist FAX : (303)497-6449
> >> > NOAA/OAR/PSD R/PSD1 Email :
> Jef...@no...
> >> > 325 Broadway Office : Skaggs Research Cntr
> 1D-113
> >> > Boulder, CO, USA 80303-3328 Web :
> http://tinyurl.com/5telg
> >> >
> >> >
> >> >
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> > This SF.net email is sponsored by:
> >> > SourcForge Community
> >> > SourceForge wants to tell your story.
> >> > http://p.sf.net/sfu/sf-spreadtheword
> >> > _______________________________________________
> >> > Matplotlib-users mailing list
> >> > Mat...@li...
> >> >
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >> >
> >>
> >> I'm not sure if this is entirely what you (Eli) are looking
> for, but I
> >> have code that will contour model data on a map and then
> extract the
> >> lat,lon pairs of all the vertices. If this is what you are
> looking
> >> for, I'm happy to share what I've done.
> >>
> >> -Patrick
> >>
> >> --
> >> Patrick Marsh
> >> Graduate Research Assistant
> >> School of Meteorology
> >> University of Oklahoma
> >> http://www.patricktmarsh.com
> >
> >
> 
> 
> 
> 
> --
> 
> Patrick Marsh
> Graduate Research Assistant
> School of Meteorology
> University of Oklahoma
> http://www.patricktmarsh.com
> 
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users
-- 
Lionel Roubeyrie
chargé d'études
LIMAIR - La Surveillance de l'Air en Limousin
http://www.limair.asso.fr
From: Michael D. <md...@st...> - 2009年02月02日 13:28:15
matplotlib uses some C-based contouring code that began life in GIST. 
You can see it here:
http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/src/cntr.c?revision=5781&view=markup
It has some limitations, notably around certain donut-shaped contours, 
and a number of us have made attempts to improve it or replace it with 
something else suitably licensed, but that's the best we've been able to 
do for now.
Mike
Lionel Roubeyrie wrote:
> Hi all,
> just a little question : how matplotlib computes contours? Is it based
> on an internal library? Is it possible to access it from outside?
> Thanks
>
> Le vendredi 30 janvier 2009 à 10:22 -0500, Eli Brosh a écrit :
> 
>> Hello again,
>> I finally found the command I was looking for. It is the
>> to_polygons().
>> Here is what worked :
>>
>> # make a LineCollection of contours
>> col=contour(X,Y,Z,LevelsNumber).collections
>>
>>
>> for i in np.arange(0,LevelsNumber,1):
>> polygoni=col[i].get_paths()[0].to_polygons()[0]
>> print polygoni
>>
>> All the vertices in each collections are extracted to the "polygoni".
>>
>> Thanks again to Jeff and Patrick !
>>
>> By the way, I found out that I do not actually need this procedure to
>> achieve may goal 
>> which was to make a contour plot in ternary coordinates.
>>
>> Eli
>>
>>
>>
>> On Tue, Jan 27, 2009 at 11:08 PM, Patrick Marsh
>> <pat...@gm...> wrote:
>> On Tue, Jan 27, 2009 at 7:16 PM, Eli Brosh <eb...@gm...>
>> wrote:
>> > Many thanks to Jeff and to Patric !
>> > I will try to work along the line suggested by Jeff.
>> > Patric, please send me your code.
>> > I hope to learn from it.
>> >
>> > Thanks again,
>> > Eli
>> 
>> 
>> 
>> Here is a template that can be used. I use this for
>> meteorological
>> models, but should work with any gridded file.
>> 
>> 
>> import numpy as np
>> from mpl_toolkits.basemap import Basemap
>> 
>> f = (some gridded file)
>> X = np.array(grab longitudes from f)
>> Y = np.array(grab latitudes from f)
>> field = np.array(grab field to be contoured from f)
>> map = Basemap(make a Basemap call here)
>> level = np.arange(minval, maxval, interval)
>> col = map.contour(X, Y, field, level).collections
>> 
>> for vertex in col[i].get_paths(): # GET THE PATHS FOR THE
>> EACH
>> CONTOUR BY LOOPING THROUGH CONTOURS
>> for vertex in xy.vertices: # ITERATE OVER THE PATH
>> OBJECTS
>> x, y = map(vertex[0],vertex[1],inverse=True) #
>> vertex[0]
>> and now 'x' is the longitude of the vertex and vertex[1] and
>> now 'y'
>> is the latitude of the vertex
>> 
>> 
>> Let me know how this works.
>> 
>> -Patrick
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> >
>> > On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh
>> <pat...@gm...>
>> > wrote:
>> >>
>> >> On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker
>> <js...@fa...> wrote:
>> >> > Eli Brosh wrote:
>> >> >> Hello,
>> >> >> I am trying to extract the coordinates of contour lines.
>> >> >> I tried the following:
>> >> >>
>> >> >> cs = *contour*(Z)
>> >> >> for lev, col in zip(cs.levels, cs.collections):
>> >> >> s = col._segments
>> >> >>
>> >> >> that I found in a previous post (title "contouring", by
>> Jose
>> >> >> Gómez-Dans-2
>> <http://www.nabble.com/user/UserProfile.jtp?user=30071>
>> >> >> Nov 30, 2007; 07:47am ) .
>> >> >>
>> >> >> I hoped that s will be a list of numpy arrays, each
>> containing the
>> >> >> (x,y) vertices
>> >> >> defining a contour line at level lev.
>> >> >> However, I got an error message:
>> >> >> AttributeError: 'LineCollection' object has no attribute
>> '_segments'
>> >> >>
>> >> >>
>> >> >> How is it possible to get coordinates of the contours,
>> similar to the
>> >> >> MATLAB command
>> >> >> [C,H] = *CONTOUR*(...)
>> >> >> where the result in C is the coordinates of the
>> contours.
>> >> >>
>> >> >> A similar question appeared in a post "contour data" (by
>> Albert Swart
>> >> >> <http://www.nabble.com/user/UserProfile.jtp?user=382945>
>> May 17, 2006;
>> >> >> 09:42am) but I could not understand the answer.
>> >> >> Is it possible to get more specific directions with a
>> simple example ?
>> >> >>
>> >> >>
>> >> >> Thanks
>> >> >> Eli
>> >> > Eli: Calling get_paths() on each line collection in
>> CS.collections will
>> >> > return a list of Path objects. From the Path objects,
>> you can get a Nx2
>> >> > array of vertices from the "vertices" attribute. There
>> are no examples
>> >> > that I know of, but if you get it to do what you want to
>> do, it would be
>> >> > great if you could contribute an example. As you noted,
>> this question
>> >> > has come up several times before.
>> >> >
>> >> > -Jeff
>> >> >
>> >> > --
>> >> > Jeffrey S. Whitaker Phone : (303)497-6313
>> >> > Meteorologist FAX : (303)497-6449
>> >> > NOAA/OAR/PSD R/PSD1 Email :
>> Jef...@no...
>> >> > 325 Broadway Office : Skaggs Research Cntr
>> 1D-113
>> >> > Boulder, CO, USA 80303-3328 Web :
>> http://tinyurl.com/5telg
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> ------------------------------------------------------------------------------
>> >> > This SF.net email is sponsored by:
>> >> > SourcForge Community
>> >> > SourceForge wants to tell your story.
>> >> > http://p.sf.net/sfu/sf-spreadtheword
>> >> > _______________________________________________
>> >> > Matplotlib-users mailing list
>> >> > Mat...@li...
>> >> >
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> >> >
>> >>
>> >> I'm not sure if this is entirely what you (Eli) are looking
>> for, but I
>> >> have code that will contour model data on a map and then
>> extract the
>> >> lat,lon pairs of all the vertices. If this is what you are
>> looking
>> >> for, I'm happy to share what I've done.
>> >>
>> >> -Patrick
>> >>
>> >> --
>> >> Patrick Marsh
>> >> Graduate Research Assistant
>> >> School of Meteorology
>> >> University of Oklahoma
>> >> http://www.patricktmarsh.com
>> >
>> >
>> 
>> 
>> 
>> 
>> --
>> 
>> Patrick Marsh
>> Graduate Research Assistant
>> School of Meteorology
>> University of Oklahoma
>> http://www.patricktmarsh.com
>> 
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by:
>> SourcForge Community
>> SourceForge wants to tell your story.
>> http://p.sf.net/sfu/sf-spreadtheword
>> _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> 
-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /