8000 Add an Annulus patch class by astromancer · Pull Request #9888 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add an Annulus patch class #9888

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

Merged
merged 18 commits into from
Apr 15, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update setters
  • Loading branch information
astromancer committed Mar 27, 2021
commit 0882ed870010eb470b663efa49432abc9b92cf6c
44 changes: 28 additions & 16 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,19 +1579,9 @@ def __init__(self, xy, r, width, angle=0.0, **kwargs):
"""
super().__init__(**kwargs)

if np.shape(r) == (2,):
self.a, self.b = r
elif np.shape(r) == ():
self.a = self.b = float(r)
else:
raise ValueError("Parameter 'r' must be one or two floats")

if min(self.a, self.b) <= width:
raise ValueError(
'Width of annulus must be smaller than semi-minor axis')

self._center = xy
self._width = width
self.set_radii(r)
self.center = xy
self.width = width
self.angle = angle
self._path = None

Expand All @@ -1613,6 +1603,7 @@ def set_center(self, xy):
xy : (float, float)
"""
self._center = xy
self._path = None
self.stale = True

def get_center(self):
Expand All @@ -1629,7 +1620,12 @@ def set_width(self, width):
----------
width : float
"""
if min(self.a, self.b) <= width:
raise ValueError(
'Width of annulus must be smaller than semi-minor axis')

self._width = width
self._path = None
self.stale = True

def get_width(self):
Expand All @@ -1649,6 +1645,7 @@ def set_angle(self, angle):
angle : float
"""
self._angle = angle
self._path = None
self.stale = True

def get_angle(self):
Expand All @@ -1666,6 +1663,7 @@ def set_semimajor(self, a):
a : float
"""
self.a = float(a)
self._path = None
self.stale = True

def set_semiminor(self, b):
Expand All @@ -1677,20 +1675,34 @@ def set_semiminor(self, b):
b : float
"""
self.b = float(b)
self._path = None
self.stale = True

def set_radii(self, radii):
def set_radii(self, r):
"""
Set the both the semi-major (*a*) and -minor radii (*b*) of the
annulus.

Parameters
----------
radii : (float, float)
r : (float, float)
"""
self.a, self.b = radii
if np.shape(r) == (2,):
self.a, self.b = r
elif np.shape(r) == ():
self.a = self.b = float(r)
else:
raise ValueError("Parameter 'r' must be one or two floats.")

self._path = None
self.stale = True

def get_radii(self):
return self.a, self.b

# alias
radii = property(get_radii, set_radii)

def _transform_verts(self, verts, a, b):
return transforms.Affine2D() \
.scale(*self._convert_xy_units((a, b))) \
Expand Down
0