Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions regions/core/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ def _make_annulus_path(patch_inner, patch_outer):

return mpath.Path(verts, codes)


def as_artists(self, origin=(0, 0), **kwargs):
"""
Return a list of patches for the composite region.
"""
# recursively retrieve all artist patches
if hasattr(self.region1, 'as_artists'):
r1p = self.region1.as_artists(origin=origin, **kwargs)
else:
r1p = [self.region1.as_artist(origin=origin, **kwargs)]
if hasattr(self.region2, 'as_artists'):
r2p = self.region2.as_artists(origin=origin, **kwargs)
else:
r2p = [self.region2.as_artist(origin=origin, **kwargs)]
return r1p + r2p


def as_artist(self, origin=(0, 0), **kwargs):
"""
Return a matplotlib patch object for this region
Expand All @@ -143,8 +160,10 @@ def as_artist(self, origin=(0, 0), **kwargs):
patch : `~matplotlib.patches.PathPatch`
A matplotlib patch object.
"""
if (self.region1.center == self.region2.center
and self.operator is op.xor):
if (hasattr(self.region1, 'center') and
hasattr(self.region2, 'center') and
self.region1.center == self.region2.center and
self.operator is op.xor):

import matplotlib.patches as mpatches

Expand Down
14 changes: 10 additions & 4 deletions regions/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,16 @@ def plot(self, origin=(0, 0), ax=None, **kwargs):
if ax is None:
ax = plt.gca()

artist = self.as_artist(origin=origin, **kwargs)
ax.add_artist(artist)

return artist
if hasattr(self, 'as_artists'):
artists = self.as_artists(origin=origin, **kwargs)
for artist in artists:
ax.add_artist(artist)
return artists
else:
artist = self.as_artist(origin=origin, **kwargs)
ax.add_artist(artist)

return artist


class SkyRegion(Region):
Expand Down