Skip to content

Commit 66a94a2

Browse files
committed
Add some helper methods to Patches
1 parent c13033f commit 66a94a2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/matplotlib/patches.py

+32
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,24 @@ def get_xy(self):
806806
"""Return the left and bottom coords of the rectangle as a tuple."""
807807
return self._x0, self._y0
808808

809+
def get_edge_midpoints(self):
810+
"""
811+
Return the edge midpoints of the rectangle, moving clockwise from the
812+
center of the left-hand edge.
813+
"""
814+
return self.get_patch_transform().transform(
815+
[(0, 0.5), (0.5, 1), (1, 0.5), (0.5, 0)])
816+
817+
def get_corners(self):
818+
"""
819+
Return the corners of the rectangle, moving clockwise from (x, y).
820+
"""
821+
return self.get_patch_transform().transform(
822+
[(0, 0), (1, 0), (1, 1), (0, 1)])
823+
824+
def get_center(self):
825+
return self.get_patch_transform().transform((0.5, 0.5))
826+
809827
def get_width(self):
810828
"""Return the width of the rectangle."""
811829
return self._width
@@ -1657,6 +1675,20 @@ def get_angle(self):
16571675

16581676
angle = property(get_angle, set_angle)
16591677

1678+
def get_corners(self):
1679+
"""
1680+
Return the corners of the rectangle, moving clockwise from (x0, y0).
1681+
"""
1682+
return self.get_patch_transform().transform(
1683+
[(-1, -1), (1, -1), (1, 1), (-1, 1)])
1684+
1685+
def get_edge_midpoints(self):
1686+
"""
1687+
Return the corners of the rectangle, moving clockwise from (x, y).
1688+
"""
1689+
return self.get_patch_transform().transform(
1690+
[(0, -1), (1, 0), (0, 1), (-1, 0)])
1691+
16601692

16611693
class Annulus(Patch):
16621694
"""

0 commit comments

Comments
 (0)