diff --git a/regions/core/compound.py b/regions/core/compound.py index a26b7da3..8c38cf96 100644 --- a/regions/core/compound.py +++ b/regions/core/compound.py @@ -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 @@ -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 diff --git a/regions/core/core.py b/regions/core/core.py index ea7e6017..f996bb7c 100644 --- a/regions/core/core.py +++ b/regions/core/core.py @@ -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):