Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa07f70

Browse files
dhomeierdstansby
andcommitted
Use display coordinates for RectangleSelector, update handles on resize
Co-authored-by: David Stansby <[email protected]>
1 parent 62d667c commit aa07f70

File tree

2 files changed

+327
-205
lines changed

2 files changed

+327
-205
lines changed

lib/matplotlib/patches.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,6 @@ def __init__(self, xy, width, height, *,
766766
self._height = height
767767
self.angle = float(angle)
768768
self.rotation_point = rotation_point
769-
# Required for RectangleSelector with axes aspect ratio != 1
770-
# The patch is defined in data coordinates and when changing the
771-
# selector with square modifier and not in data coordinates, we need
772-
# to correct for the aspect ratio difference between the data and
773-
# display coordinate systems. Its value is typically provide by
774-
# Axes._get_aspect_ratio()
775-
self._aspect_ratio_correction = 1.0
776769
self._convert_units() # Validate the inputs.
777770

778771
def get_path(self):
@@ -800,13 +793,11 @@ def get_patch_transform(self):
800793
rotation_point = bbox.x0, bbox.y0
801794
else:
802795
rotation_point = self.rotation_point
803-
return transforms.BboxTransformTo(bbox) \
804-
+ transforms.Affine2D() \
805-
.translate(-rotation_point[0], -rotation_point[1]) \
806-
.scale(1, self._aspect_ratio_correction) \
807-
.rotate_deg(self.angle) \
808-
.scale(1, 1 / self._aspect_ratio_correction) \
809-
.translate(*rotation_point)
796+
return (transforms.BboxTransformTo(bbox) +
797+
transforms.Affine2D()
798+
.translate(-rotation_point[0], -rotation_point[1])
799+
.rotate_deg(self.angle)
800+
.translate(*rotation_point))
810801

811802
@property
812803
def rotation_point(self):
@@ -1625,12 +1616,6 @@ def __init__(self, xy, width, height, *, angle=0, **kwargs):
16251616
self._width, self._height = width, height
16261617
self._angle = angle
16271618
self._path = Path.unit_circle()
1628-
# Required for EllipseSelector with axes aspect ratio != 1
1629-
# The patch is defined in data coordinates and when changing the
1630-
# selector with square modifier and not in data coordinates, we need
1631-
# to correct for the aspect ratio difference between the data and
1632-
# display coordinate systems.
1633-
self._aspect_ratio_correction = 1.0
16341619
# Note: This cannot be calculated until this is added to an Axes
16351620
self._patch_transform = transforms.IdentityTransform()
16361621

@@ -1648,9 +1633,8 @@ def _recompute_transform(self):
16481633
width = self.convert_xunits(self._width)
16491634
height = self.convert_yunits(self._height)
16501635
self._patch_transform = transforms.Affine2D() \
1651-
.scale(width * 0.5, height * 0.5 * self._aspect_ratio_correction) \
1636+
.scale(width * 0.5, height * 0.5) \
16521637
.rotate_deg(self.angle) \
1653-
.scale(1, 1 / self._aspect_ratio_correction) \
16541638
.translate(*center)
16551639

16561640
def get_path(self):

0 commit comments

Comments
 (0)