Discussion:
[Matplotlib-users] creating a path from multiple sets of xy coordinates (inner and outer outlines)
Denis-Alexander Engemann
2014-12-19 23:01:01 UTC
Permalink
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
Phil Elson
2014-12-22 11:09:04 UTC
Permalink
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')
axes.add_patch(patch)


HTH,

Phil


On 19 December 2014 at 23:01, Denis-Alexander Engemann <
Post by Denis-Alexander Engemann
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
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Denis-Alexander Engemann
2014-12-22 11:15:48 UTC
Permalink
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
Post by Phil Elson
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
http://matplotlib.org/examples/pylab_examples/marker_path.html
import matplotlib.patches as mpatches
patch = mpatches.PathPatch(my_path, facecolor='red', edgecolor='yellow')
axes.add_patch(patch)
HTH,
Phil
On 19 December 2014 at 23:01, Denis-Alexander Engemann <
Post by Denis-Alexander Engemann
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
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Ryan Nelson
2014-12-22 14:38:21 UTC
Permalink
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 <
Post by Denis-Alexander Engemann
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
Post by Phil Elson
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
http://matplotlib.org/examples/pylab_examples/marker_path.html
import matplotlib.patches as mpatches
patch = mpatches.PathPatch(my_path, facecolor='red', edgecolor='yellow')
axes.add_patch(patch)
HTH,
Phil
On 19 December 2014 at 23:01, Denis-Alexander Engemann <
Post by Denis-Alexander Engemann
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
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
------------------------------------------------------------------------------
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
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Phil Elson
2014-12-23 11:27:20 UTC
Permalink
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 <
Post by Denis-Alexander Engemann
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
Post by Phil Elson
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
http://matplotlib.org/examples/pylab_examples/marker_path.html
import matplotlib.patches as mpatches
patch = mpatches.PathPatch(my_path, facecolor='red', edgecolor='yellow')
axes.add_patch(patch)
HTH,
Phil
On 19 December 2014 at 23:01, Denis-Alexander Engemann <
Post by Denis-Alexander Engemann
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
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Denis-Alexander Engemann
2015-04-17 16:37:20 UTC
Permalink
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
Post by Phil Elson
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 <
Post by Denis-Alexander Engemann
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
Post by Phil Elson
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
http://matplotlib.org/examples/pylab_examples/marker_path.html
import matplotlib.patches as mpatches
patch = mpatches.PathPatch(my_path, facecolor='red', edgecolor='yellow')
axes.add_patch(patch)
HTH,
Phil
On 19 December 2014 at 23:01, Denis-Alexander Engemann <
Post by Denis-Alexander Engemann
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
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...