Delay WCSAxes import
@@ -5,7 +5,6 @@ from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy.table import Table
from astropy.wcs import WCS
-from astropy.visualization.wcsaxes import WCSAxes
from astropy.wcs.utils import proj_plane_pixel_area, wcs_to_celestial_frame
from regions import FITSRegionParser, fits_region_objects_to_table
@@ -461,18 +460,23 @@ class RegionGeom(Geom):
"""
import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection
+ from astropy.visualization.wcsaxes import WCSAxes
if ax is None:
ax = plt.gca()
+
if not isinstance(ax, WCSAxes):
ax.remove()
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]
+
kwargs.setdefault("fc", "None")
kwargs.setdefault("ec", "b")
+
patches = PatchCollection(artists, **kwargs)
ax.add_collection(patches)
return ax
