diff --git a/docs/plot_example.py b/docs/plot_example.py index c650e9dc..753cff23 100644 --- a/docs/plot_example.py +++ b/docs/plot_example.py @@ -28,5 +28,6 @@ pix_region = region.to_pixel(wcs=wcs) pix_region.plot(ax=ax, edgecolor='yellow', facecolor='yellow', alpha=0.5, lw=3) + region.plot(edgecolor='red', lw=1) plt.show() diff --git a/regions/core/core.py b/regions/core/core.py index 7315b49a..6c31bb0e 100644 --- a/regions/core/core.py +++ b/regions/core/core.py @@ -378,3 +378,26 @@ def to_pixel(self, wcs): pixel_region : `~regions.PixelRegion` object. """ raise NotImplementedError + + def plot(self, ax=None, **kwargs): + """ + Plot region using matplotlib. + + TODO: describe once we know what API we want. + """ + import matplotlib.pyplot as plt + + if ax is None: + ax = plt.gca() + + if not hasattr(ax, 'wcs'): + raise TypeError( + 'SkyRegion plot only works on WCSAxes. ' + 'Consider using WCSAxes or use sky_region.to_pixel(wcs).plot(...).' + ) + + pix_region = self.to_pixel(ax.wcs) + artist = pix_region.as_artist(**kwargs) + ax.add_artist(artist) + + return ax diff --git a/regions/core/tests/test_core.py b/regions/core/tests/test_core.py new file mode 100644 index 00000000..58a90112 --- /dev/null +++ b/regions/core/tests/test_core.py @@ -0,0 +1,16 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +from __future__ import absolute_import, division, print_function, unicode_literals +import pytest +from ...shapes import CircleSkyRegion, PointSkyRegion + +try: + import matplotlib + + HAS_MATPLOTLIB = True +except: + HAS_MATPLOTLIB = False + + +@pytest.mark.skipif('not HAS_MATPLOTLIB') +def test_sky_region_plot(): + assert 'TODO'