# creating a path from multiple sets of xy coordinates (inner and outer outlines)

Dear list,

I would like to create a custom image clipping mask using patches. My constraint is that my patch is required to have an outer and multiple inner outlines.

To provide an analogy, think of a mask used for disguise where you leave three holes, two for the eyes, one for the mouth.

I have the xy coordinates for the ‘head’, and the xy coordinates for each of the holes that I don’t want to be hidden by the ensuing clipping mask.

What’s the matplotlib way to construct my desired path + patch from that?

Note, it’s important in my case to use a patch object. What I need to do would not work by simply masking my image using a masked array.

Any pointer would be highly appreciated –

Denis

Sorry its taken so long to get an answer, but essentially you want to concatenate the outer coordinates with the inner ones (reversed) to indicate that it is a hole. There is a pretty (simple) useful example that I added a few years ago for demonstrating the use of paths for markers: http://matplotlib.org/examples/pylab_examples/marker_path.html

Constructing a patch from a path is as simple as (untested):

import matplotlib.patches as mpatches

patch = mpatches.PathPatch(my_path, facecolor=‘red’, edgecolor=‘yellow’)

HTH,

Phil

···

On 19 December 2014 at 23:01, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Dear list,

I would like to create a custom image clipping mask using patches. My constraint is that my patch is required to have an outer and multiple inner outlines.

To provide an analogy, think of a mask used for disguise where you leave three holes, two for the eyes, one for the mouth.

I have the xy coordinates for the ‘head’, and the xy coordinates for each of the holes that I don’t want to be hidden by the ensuing clipping mask.

What’s the matplotlib way to construct my desired path + patch from that?

Note, it’s important in my case to use a patch object. What I need to do would not work by simply masking my image using a masked array.

Any pointer would be highly appreciated –

Denis

Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Thanks Phil,

just to make sure I inderstand the logic of PathPatch. Does it cut out vertices / paths that are detected to be inside an outline as the star in this example?

-Denis

···

2014-12-22 12:09 GMT+01:00 Phil Elson <pelson.pub@…83…287…>:

Sorry its taken so long to get an answer, but essentially you want to concatenate the outer coordinates with the inner ones (reversed) to indicate that it is a hole. There is a pretty (simple) useful example that I added a few years ago for demonstrating the use of paths for markers: http://matplotlib.org/examples/pylab_examples/marker_path.html

Constructing a patch from a path is as simple as (untested):

import matplotlib.patches as mpatches

patch = mpatches.PathPatch(my_path, facecolor=‘red’, edgecolor=‘yellow’)

HTH,

Phil

On 19 December 2014 at 23:01, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Dear list,

I would like to create a custom image clipping mask using patches. My constraint is that my patch is required to have an outer and multiple inner outlines.

To provide an analogy, think of a mask used for disguise where you leave three holes, two for the eyes, one for the mouth.

I have the xy coordinates for the ‘head’, and the xy coordinates for each of the holes that I don’t want to be hidden by the ensuing clipping mask.

What’s the matplotlib way to construct my desired path + patch from that?

Note, it’s important in my case to use a patch object. What I need to do would not work by simply masking my image using a masked array.

Any pointer would be highly appreciated –

Denis

Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Denis,

I’ve only made simple polygons with MPL, so I don’t know the full capabilities. However, there is another package called Shapely that can construct polygons like you’ve defined:

http://toblerity.org/shapely/manual.html#polygons

It also does some set-type stuff, such as intersections, differences, etc. Might be overkill, but it should do what you want.

Ryan

(Meant to send this to the list as well, Denis. Sorry for the repeat.)

···

On Mon, Dec 22, 2014 at 6:15 AM, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Thanks Phil,

just to make sure I inderstand the logic of PathPatch. Does it cut out vertices / paths that are detected to be inside an outline as the star in this example?

-Denis

Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

2014-12-22 12:09 GMT+01:00 Phil Elson <pelson.pub@…287…>:

Sorry its taken so long to get an answer, but essentially you want to concatenate the outer coordinates with the inner ones (reversed) to indicate that it is a hole. There is a pretty (simple) useful example that I added a few years ago for demonstrating the use of paths for markers: http://matplotlib.org/examples/pylab_examples/marker_path.html

Constructing a patch from a path is as simple as (untested):

import matplotlib.patches as mpatches

patch = mpatches.PathPatch(my_path, facecolor=‘red’, edgecolor=‘yellow’)

HTH,

Phil

On 19 December 2014 at 23:01, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Dear list,

I would like to create a custom image clipping mask using patches. My constraint is that my patch is required to have an outer and multiple inner outlines.

To provide an analogy, think of a mask used for disguise where you leave three holes, two for the eyes, one for the mouth.

I have the xy coordinates for the ‘head’, and the xy coordinates for each of the holes that I don’t want to be hidden by the ensuing clipping mask.

What’s the matplotlib way to construct my desired path + patch from that?

Note, it’s important in my case to use a patch object. What I need to do would not work by simply masking my image using a masked array.

Any pointer would be highly appreciated –

Denis

Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

If I understand your question fully, then yes it does.
Have a play, and let us know how you get on.

Best,

Phil

···

On 22 December 2014 at 11:15, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Thanks Phil,

just to make sure I inderstand the logic of PathPatch. Does it cut out vertices / paths that are detected to be inside an outline as the star in this example?

-Denis

2014-12-22 12:09 GMT+01:00 Phil Elson <pelson.pub@…287…>:

Sorry its taken so long to get an answer, but essentially you want to concatenate the outer coordinates with the inner ones (reversed) to indicate that it is a hole. There is a pretty (simple) useful example that I added a few years ago for demonstrating the use of paths for markers: http://matplotlib.org/examples/pylab_examples/marker_path.html

Constructing a patch from a path is as simple as (untested):

import matplotlib.patches as mpatches

patch = mpatches.PathPatch(my_path, facecolor=‘red’, edgecolor=‘yellow’)

HTH,

Phil

On 19 December 2014 at 23:01, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Dear list,

I would like to create a custom image clipping mask using patches. My constraint is that my patch is required to have an outer and multiple inner outlines.

To provide an analogy, think of a mask used for disguise where you leave three holes, two for the eyes, one for the mouth.

I have the xy coordinates for the ‘head’, and the xy coordinates for each of the holes that I don’t want to be hidden by the ensuing clipping mask.

What’s the matplotlib way to construct my desired path + patch from that?

Note, it’s important in my case to use a patch object. What I need to do would not work by simply masking my image using a masked array.

Any pointer would be highly appreciated –

Denis

Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Thanks everyone,
I finally got back to this, your suggestions worked like a charme,

example outputs can be seen here:

https://github.com/mne-tools/mne-python/pull/1972

Best,

Denis

···

2014-12-23 12:27 GMT+01:00 Phil Elson <pelson.pub@…287…>:

If I understand your question fully, then yes it does.
Have a play, and let us know how you get on.

Best,

Phil

On 22 December 2014 at 11:15, Denis-Alexander Engemann <denis.engemann@…1003…7…> wrote:

Thanks Phil,

just to make sure I inderstand the logic of PathPatch. Does it cut out vertices / paths that are detected to be inside an outline as the star in this example?

-Denis

2014-12-22 12:09 GMT+01:00 Phil Elson <pelson.pub@…287…>:

Sorry its taken so long to get an answer, but essentially you want to concatenate the outer coordinates with the inner ones (reversed) to indicate that it is a hole. There is a pretty (simple) useful example that I added a few years ago for demonstrating the use of paths for markers: http://matplotlib.org/examples/pylab_examples/marker_path.html

Constructing a patch from a path is as simple as (untested):

import matplotlib.patches as mpatches

patch = mpatches.PathPatch(my_path, facecolor=‘red’, edgecolor=‘yellow’)

HTH,

Phil

On 19 December 2014 at 23:01, Denis-Alexander Engemann <denis.engemann@…287…> wrote:

Dear list,

I would like to create a custom image clipping mask using patches. My constraint is that my patch is required to have an outer and multiple inner outlines.

To provide an analogy, think of a mask used for disguise where you leave three holes, two for the eyes, one for the mouth.

I have the xy coordinates for the ‘head’, and the xy coordinates for each of the holes that I don’t want to be hidden by the ensuing clipping mask.

What’s the matplotlib way to construct my desired path + patch from that?

Note, it’s important in my case to use a patch object. What I need to do would not work by simply masking my image using a masked array.

Any pointer would be highly appreciated –

Denis

Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE