Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sky region plot #221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
23 changes: 23 additions & 0 deletions regions/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions regions/core/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -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'