selecting part of a contour to plot

To all:

I'm making a plot with an image and a contour on it. I use only one
level in the call to contour, but it results in two distinct contours,
an inner closed one and an outer open one. I want to plot only the
outer piece. How might I go about that? I've been looking at the
properties of the ContourSet object returned by the call to contour but
can't find anything useful yet. Is there an attribute of ContourSet
objects that contains the (x,y) values for the contour? Is there some
way to see that a ContourSet object has separate pieces?

Any help would be appreciated.

Thanks,
Jon

Jon,

One thing you can do is to manually specify the levels to contour for in the contour call, or just specify the number of contours (and contour() will figure out the levels for you). The fourth argument to contour() allows you to give a sequence of values (or an integer) for the isopleths. So, if you want just one line (but have it chosen automatically):

contour(x, y, z, 1)

If you want a contour to always be for the value of 4.5, for example, then:

contour(x, y, z, [4.5])

Should do the trick.

I hope that helps,
Ben Root

···

On Tue, Jun 22, 2010 at 1:46 PM, Jonathan Slavin <jslavin@…1081…> wrote:

To all:

I’m making a plot with an image and a contour on it. I use only one

level in the call to contour, but it results in two distinct contours,

an inner closed one and an outer open one. I want to plot only the

outer piece. How might I go about that? I’ve been looking at the

properties of the ContourSet object returned by the call to contour but

can’t find anything useful yet. Is there an attribute of ContourSet

objects that contains the (x,y) values for the contour? Is there some

way to see that a ContourSet object has separate pieces?

Any help would be appreciated.

Thanks,

Jon


ThinkGeek and WIRED’s GeekDad team up for the Ultimate

GeekDad Father’s Day Giveaway. ONE MASSIVE PRIZE to the

lucky parental unit. See the prize list and enter to win:

http://p.sf.net/sfu/thinkgeek-promo


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Actually, I just re-read your original message and noticed that you were specifying your levels (I believe). The double set of contours depends on what your values are. If you want to make absolutely sure that there aren’t extra lines, you could contour a boolean array:

contour(x, y, z > 4.5, [0, 1])

That should do the trick as well (assuming you know the level that you want the isopleth for).

Ben Root

···

On Tue, Jun 22, 2010 at 6:27 PM, Benjamin Root <ben.root@…1304…> wrote:

Jon,

One thing you can do is to manually specify the levels to contour for in the contour call, or just specify the number of contours (and contour() will figure out the levels for you). The fourth argument to contour() allows you to give a sequence of values (or an integer) for the isopleths. So, if you want just one line (but have it chosen automatically):

contour(x, y, z, 1)

If you want a contour to always be for the value of 4.5, for example, then:

contour(x, y, z, [4.5])

Should do the trick.

I hope that helps,
Ben Root

On Tue, Jun 22, 2010 at 1:46 PM, Jonathan Slavin <jslavin@…1081…> wrote:

To all:

I’m making a plot with an image and a contour on it. I use only one

level in the call to contour, but it results in two distinct contours,

an inner closed one and an outer open one. I want to plot only the

outer piece. How might I go about that? I’ve been looking at the

properties of the ContourSet object returned by the call to contour but

can’t find anything useful yet. Is there an attribute of ContourSet

objects that contains the (x,y) values for the contour? Is there some

way to see that a ContourSet object has separate pieces?

Any help would be appreciated.

Thanks,

Jon


ThinkGeek and WIRED’s GeekDad team up for the Ultimate

GeekDad Father’s Day Giveaway. ONE MASSIVE PRIZE to the

lucky parental unit. See the prize list and enter to win:

http://p.sf.net/sfu/thinkgeek-promo


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

contour creates list of LineCollection objects (per each level I
suppose) which is stored in "collections" attribute. For example,

cntr = contour(A, levels)

then

cntr.collections[i] is a LineCollection objects that is associated
with levels[i].

And you can change colors of each line in the LineCollection object
with set_edgecolors method.

So, assuming that there is two contour lines for the first level.

cntr.collections[0].set_edgecolors(["none", "r"])

will change the color of the first contour to "none" (i.e., not drawn)
and the second one to red.

But you need to figure out which one is the one you want.

IHTH,

-JJ

···

On Tue, Jun 22, 2010 at 2:46 PM, Jonathan Slavin <jslavin@...1081...> wrote:

To all:

I'm making a plot with an image and a contour on it. I use only one
level in the call to contour, but it results in two distinct contours,
an inner closed one and an outer open one. I want to plot only the
outer piece. How might I go about that? I've been looking at the
properties of the ContourSet object returned by the call to contour but
can't find anything useful yet. Is there an attribute of ContourSet
objects that contains the (x,y) values for the contour? Is there some
way to see that a ContourSet object has separate pieces?

Any help would be appreciated.

Thanks,
Jon

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks to Benjamin Root and Jae-Joon Lee for their responses.

The solution that I had come up with in the mean time is similar to
Jae-Joon's suggestion. I did:

c = contour(z,level,colors='k')
xy = c.collections[0].get_paths()[0].vertices # produces (N,2) array of points
plot(xy[:,0],xy[:,1],'w')

c.collections[0].get_paths() returns a list of Path objects. These have
the attribute vertices which contains the values used to draw the
contour. Jae-Joon's method is a bit more straightforward than mine,
though it's nice to know where those contour paths are stored.

Jon

···

On Tue, 2010-06-22 at 22:40 -0400, Jae-Joon Lee wrote:

contour creates list of LineCollection objects (per each level I
suppose) which is stored in "collections" attribute. For example,

cntr = contour(A, levels)

then

cntr.collections[i] is a LineCollection objects that is associated
with levels[i].

And you can change colors of each line in the LineCollection object
with set_edgecolors method.

So, assuming that there is two contour lines for the first level.

cntr.collections[0].set_edgecolors(["none", "r"])

will change the color of the first contour to "none" (i.e., not drawn)
and the second one to red.

But you need to figure out which one is the one you want.

IHTH,

-JJ

On Tue, Jun 22, 2010 at 2:46 PM, Jonathan Slavin > <jslavin@...1081...> wrote:
> To all:
>
> I'm making a plot with an image and a contour on it. I use only one
> level in the call to contour, but it results in two distinct contours,
> an inner closed one and an outer open one. I want to plot only the
> outer piece. How might I go about that? I've been looking at the
> properties of the ContourSet object returned by the call to contour but
> can't find anything useful yet. Is there an attribute of ContourSet
> objects that contains the (x,y) values for the contour? Is there some
> way to see that a ContourSet object has separate pieces?
>
> Any help would be appreciated.
>
> Thanks,
> Jon
>
>
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
> lucky parental unit. See the prize list and enter to win:
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options
>

--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________