Skip to content

Commit

Permalink
Merge pull request #389 from larrybradley/patch-fill
Browse files Browse the repository at this point in the history
Fix plotting issues
  • Loading branch information
larrybradley authored Jul 23, 2021
2 parents 4e4ed5e + 3cc0097 commit 5055128
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ Bug Fixes
- Fixed the DS9 default point symbol to use 'boxcircle'. [#387]

- Point symbol markers are no longer filled for consistency with DS9.
[387]
[#387]

- Fixed an issue where plotting elliptical regions were incorrectly
filled by default. [#389]

- Fixed an issue where compound region colors were being set correctly.
[#389]

API Changes
-----------
Expand Down
12 changes: 9 additions & 3 deletions regions/core/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def __init__(self, region1, region2, operator, meta=None, visual=None):
if meta is None:
self.meta = region1.meta
else:
self.meta = RegionMeta()
self.meta = meta
if visual is None:
self.visual = region1.visual
else:
self.visual = RegionVisual()
self.visual = visual
self._operator = operator

@property
Expand Down Expand Up @@ -147,10 +147,16 @@ def as_artist(self, origin=(0, 0), **kwargs):

import matplotlib.patches as mpatches

# set mpl_kwargs before as_artist is called on region1 and
# region2
mpl_kwargs = self._define_mpl_kwargs(artist='Patch')
mpl_kwargs.update(kwargs)

patch_inner = self.region1.as_artist(origin=origin)
patch_outer = self.region2.as_artist(origin=origin)
path = self._make_annulus_path(patch_inner, patch_outer)
patch = mpatches.PathPatch(path, **kwargs)

patch = mpatches.PathPatch(path, **mpl_kwargs)
return patch
else:
raise NotImplementedError
Expand Down
9 changes: 9 additions & 0 deletions regions/io/ds9/tests/test_ds9.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,12 @@ def test_point_boxcircle():
assert regions[1].as_artist().get_color() == 'blue'
assert isinstance(regions[2].as_artist().get_marker(), mpath.Path)
assert regions[2].as_artist().get_color() == 'green'


@pytest.mark.skipif('not HAS_MATPLOTLIB')
def test_compound_color():
regstr = ('# Region file format: DS9 astropy/regions\n'
'image\n'
'annulus(651.0,301.0,60.0,90.0) # color=red')
regions = Regions.parse(regstr, format='ds9')
assert regions[0].as_artist().get_edgecolor() == (1., 0., 0., 1.)
2 changes: 1 addition & 1 deletion regions/shapes/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def as_artist(self, origin=(0, 0), **kwargs):
mpl_kwargs.update(kwargs)

return Ellipse(xy=xy, width=width, height=height, angle=angle,
**kwargs)
**mpl_kwargs)

def _update_from_mpl_selector(self, *args, **kwargs):
xmin, xmax, ymin, ymax = self._mpl_selector.extents
Expand Down

0 comments on commit 5055128

Please sign in to comment.