8000 Update Ellipse position with ellipse.center by eschutz · Pull Request #11057 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Update Ellipse position with ellipse.center #11057

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 2 commits into from
Apr 16, 2018
Merged
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
29 changes: 24 additions & 5 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ class Ellipse(Patch):
A scale-free ellipse.
"""
def __str__(self):
pars = (self.center[0], self.center[1],
pars = (self._center[0], self._center[1],
self.width, self.height, self.angle)
fmt = "Ellipse(xy=(%s, %s), width=%s, height=%s, angle=%s)"
return fmt % pars
Expand All @@ -1439,7 +1439,7 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
"""
Patch.__init__(self, **kwargs)

self.center = xy
self._center = xy
self.width, self.height = width, height
self.angle = angle
self._path = Path.unit_circle()
Expand All @@ -1452,8 +1452,8 @@ def _recompute_transform(self):
makes it very important to call the accessor method and
not directly access the transformation member variable.
"""
center = (self.convert_xunits(self.center[0]),
self.convert_yunits(self.center[1]))
center = (self.convert_xunits(self._center[0]),
self.convert_yunits(self._center[1]))
width = self.convert_xunits(self.width)
height = self.convert_yunits(self.height)
self._patch_transform = transforms.Affine2D() \
Expand All @@ -1471,6 +1471,23 @@ def get_patch_transform(self):
self._recompute_transform()
return self._patch_transform

def set_center(self, xy):
"""
Set the center of the ellipse

ACCEPTS: (x, y)
"""
self._center = xy
self.stale = True

def get_center(self):
"""
Return the center of the ellipse
"""
return self._center

center = property(get_center, set_center)


class Circle(Ellipse):
"""
Expand Down Expand Up @@ -1506,7 +1523,9 @@ def set_radius(self, radius):
self.stale = True

def get_radius(self):
'return the radius of the circle'
"""
Return the radius of the circle
"""
return self.width / 2.

radius = property(get_radius, set_radius)
Expand Down
0