8000 Merge pull request #11057 from eschutz/ellipse-center · matplotlib/matplotlib@5daabdd · GitHub
[go: up one dir, main page]

Skip to content

Commit 5daabdd

Browse files
authored
Merge pull request #11057 from eschutz/ellipse-center
Update Ellipse position with ellipse.center
2 parents c98be63 + 134a0b6 commit 5daabdd

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

lib/matplotlib/patches.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ class Ellipse(Patch):
14141414
A scale-free ellipse.
14151415
"""
14161416
def __str__(self):
1417-
pars = (self.center[0], self.center[1],
1417+
pars = (self._center[0], self._center[1],
14181418
self.width, self.height, self.angle)
14191419
fmt = "Ellipse(xy=(%s, %s), width=%s, height=%s, angle=%s)"
14201420
return fmt % pars
@@ -1439,7 +1439,7 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
14391439
"""
14401440
Patch.__init__(self, **kwargs)
14411441

1442-
self.center = xy
1442+
self._center = xy
14431443
self.width, self.height = width, height
14441444
self.angle = angle
14451445
self._path = Path.unit_circle()
@@ -1452,8 +1452,8 @@ def _recompute_transform(self):
14521452
makes it very important to call the accessor method and
14531453
not directly access the transformation member variable.
14541454
"""
1455-
center = (self.convert_xunits(self.center[0]),
1456-
self.convert_yunits(self.center[1]))
1455+
center = (self.convert_xunits(self._center[0]),
1456+
self.convert_yunits(self._center[1]))
14571457
width = self.convert_xunits(self.width)
14581458
height = self.convert_yunits(self.height)
14591459
self._patch_transform = transforms.Affine2D() \
@@ -1471,6 +1471,23 @@ def get_patch_transform(self):
14711471
self._recompute_transform()
14721472
return self._patch_transform
14731473

1474+
def set_center(self, xy):
1475+
"""
1476+
Set the center of the ellipse
1477+
1478+
ACCEPTS: (x, y)
1479+
"""
1480+
self._center = xy
1481+
self.stale = True
1482+
1483+
def get_center(self):
1484+
"""
1485+
Return the center of the ellipse
1486+
"""
1487+
return self._center
1488+
1489+
center = property(get_center, set_center)
1490+
14741491

14751492
class Circle(Ellipse):
14761493
"""
@@ -1506,7 +1523,9 @@ def set_radius(self, radius):
15061523
self.stale = True
15071524

15081525
def get_radius(self):
1509-
'return the radius of the circle'
1526+
"""
1527+
Return the radius of the circle
1528+
"""
15101529
return self.width / 2.
15111530

15121531
radius = property(get_radius, set_radius)

0 commit comments

Comments
 (0)
0