move and add case
@@ -12,7 +12,7 @@ from gammapy.utils.regions import (
make_region,
)
from gammapy.maps.wcs import _check_width
-from .core import MapCoord
+from .core import MapCoord, Map
from .geom import Geom, MapAxes, MapAxis, pix_tuple_to_idx
from .wcs import WcsGeom
@@ -415,3 +415,29 @@ class RegionGeom(Geom):
self._region = self.region.union(other.region)
else:
self._region = other.region
+
+ def plot_region(self, ax=None, **kwargs):
+ """Plot region in the sky.
+
+ Parameters
+ ----------
+ ax : `~astropy.vizualisation.WCSAxes`
+ Axes to plot on. If no axes are given,
+ the region is shown using the minimal
+ equivalent WCS geometry.
+ **kwargs : dict
+ Keyword arguments forwarded to `~regions.PixelRegion.as_artist`
+ """
+ import matplotlib.pyplot as plt
+ from matplotlib.collections import PatchCollection
+
+ if ax is None:
+ wcs_geom = self.to_wcs_geom()
+ m = Map.from_geom(wcs_geom)
+ fig, ax, cbar = m.plot(add_cbar=False)
+ regions = compound_region_to_list(self.region)
+ artists = [region.to_pixel(wcs=ax.wcs).as_artist() for region in regions]
+
+ patches = PatchCollection(artists, **kwargs)
+ ax.add_collection(patches)
+ return ax
