8000 Make rectangle patch rotation point more generic · matplotlib/matplotlib@68d00dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 68d00dd

Browse files
committed
Make rectangle patch rotation point more generic
1 parent c403fb9 commit 68d00dd

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/matplotlib/patches.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ def __str__(self):
706706
return fmt % pars
707707

708708
@docstring.dedent_interpd
709-
def __init__(self, xy, width, height, angle=0.0,
710-
rotate_around_center=False, **kwargs):
709+
def __init__(self, xy, width, height, angle=0.0, *,
710+
rotation_point='xy', **kwargs):
711711
"""
712712
Parameters
713713
----------
@@ -718,12 +718,11 @@ def __init__(self, xy, width, height, angle=0.0,
718718
height : float
719719
Rectangle height.
720720
angle : float, default: 0
721-
Rotation in degrees anti-clockwise about *xy* if
722-
*rotate_around_center* if False, otherwise rotate around the
723-
center of the rectangle
724-
rotate_around_center : bool, default: False
725-
If True, the rotation is performed around the center of the
726-
rectangle.
721+
Rotation in degrees anti-clockwise about the rotation point.
722+
rotation_point : {'xy', 'center', (number, number)}, default: 'xy'
723+
If ``'xy'``, rotate around the anchor point. If ``'center'`` rotate
724+
around the center. If 2-tuple of number, rotate around these
725+
coordinate.
727726
728727
Other Parameters
729728
----------------
@@ -736,7 +735,7 @@ def __init__(self, xy, width, height, angle=0.0,
736735
self._width = width
737736
self._height = height
738737
self.angle = float(angle)
739-
self.rotate_around_center = rotate_around_center
738+
self.rotation_point = rotation_point
740739
# Required for RectangleSelector with axes aspect ratio != 1
741740
# The patch is defined in data coordinates and when changing the
742741
# selector with square modifier and not in data coordinates, we need
@@ -763,11 +762,14 @@ def get_patch_transform(self):
763762
# important to call the accessor method and not directly access the
764763
# transformation member variable.
765764
bbox = self.get_bbox()
766-
if self.rotate_around_center:
765+
if self.rotation_point == 'center':
767766
width, height = bbox.x1 - bbox.x0, bbox.y1 - bbox.y0
768767
rotation_point = bbox.x0 + width / 2., bbox.y0 + height / 2.
769-
else:
768+
elif self.rotation_point == 'xy':
770769
rotation_point = bbox.x0, bbox.y0
770+
elif (isinstance(self.rotation_point[0], Number) and
771+
isinstance(self.rotation_point[1], Number)):
772+
rotation_point = self.rotation_point
771773
return transforms.BboxTransformTo(bbox) \
772774
+ transforms.Affine2D() \
773775
.translate(-rotation_point[0], -rotation_point[1]) \
@@ -1534,6 +1536,10 @@ def __init__(self, xy, width, height, angle=0, **kwargs):
15341536
self._angle = angle
15351537
self._path = Path.unit_circle()
15361538
# Required for EllipseSelector with axes aspect ratio != 1
1539+
# The patch is defined in data coordinates and when changing the
1540+
# selector with square modifier and not in data coordinates, we need
1541+
# to correct for the aspect ratio difference between the data and
1542+
# display coordinate systems.
15371543
self._aspect_ratio_correction = 1.0
15381544
# Note: This cannot be calculated until this is added to an Axes
15391545
self._patch_transform = transforms.IdentityTransform()

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,7 @@ def _handles_artists(self):
29482948

29492949
def _init_shape(self, **props):
29502950
return Rectangle((0, 0), 0, 1, visible=False,
2951-
rotate_around_center=True, **props)
2951+
rotation_point='center', **props)
29522952

29532953
def _press(self, event):
29542954
"""Button press event handler."""

0 commit comments

Comments
 (0)
0