Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0484b1d

Browse filesBrowse files
dhomeierdstansby
andcommitted
Use display coordinates for RectangleSelector, update handles on resize
Co-authored-by: David Stansby <dstansby@gmail.com>
1 parent d238b8e commit 0484b1d
Copy full SHA for 0484b1d

File tree

2 files changed

+327
-205
lines changed
Filter options

2 files changed

+327
-205
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+6-22Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,6 @@ def __init__(self, xy, width, height, *,
722722
self._height = height
723723
self.angle = float(angle)
724724
self.rotation_point = rotation_point
725-
# Required for RectangleSelector with axes aspect ratio != 1
726-
# The patch is defined in data coordinates and when changing the
727-
# selector with square modifier and not in data coordinates, we need
728-
# to correct for the aspect ratio difference between the data and
729-
# display coordinate systems. Its value is typically provide by
730-
# Axes._get_aspect_ratio()
731-
self._aspect_ratio_correction = 1.0
732725
self._convert_units() # Validate the inputs.
733726

734727
def get_path(self):
@@ -756,13 +749,11 @@ def get_patch_transform(self):
756749
rotation_point = bbox.x0, bbox.y0
757750
else:
758751
rotation_point = self.rotation_point
759-
return transforms.BboxTransformTo(bbox) \
760-
+ transforms.Affine2D() \
761-
.translate(-rotation_point[0], -rotation_point[1]) \
762-
.scale(1, self._aspect_ratio_correction) \
763-
.rotate_deg(self.angle) \
764-
.scale(1, 1 / self._aspect_ratio_correction) \
765-
.translate(*rotation_point)
752+
return (transforms.BboxTransformTo(bbox) +
753+
transforms.Affine2D()
754+
.translate(-rotation_point[0], -rotation_point[1])
755+
.rotate_deg(self.angle)
756+
.translate(*rotation_point))
766757

767758
@property
768759
def rotation_point(self):
@@ -1553,12 +1544,6 @@ def __init__(self, xy, width, height, *, angle=0, **kwargs):
15531544
self._width, self._height = width, height
15541545
self._angle = angle
15551546
self._path = Path.unit_circle()
1556-
# Required for EllipseSelector with axes aspect ratio != 1
1557-
# The patch is defined in data coordinates and when changing the
1558-
# selector with square modifier and not in data coordinates, we need
1559-
# to correct for the aspect ratio difference between the data and
1560-
# display coordinate systems.
1561-
self._aspect_ratio_correction = 1.0
15621547
# Note: This cannot be calculated until this is added to an Axes
15631548
self._patch_transform = transforms.IdentityTransform()
15641549

@@ -1576,9 +1561,8 @@ def _recompute_transform(self):
15761561
width = self.convert_xunits(self._width)
15771562
height = self.convert_yunits(self._height)
15781563
self._patch_transform = transforms.Affine2D() \
1579-
.scale(width * 0.5, height * 0.5 * self._aspect_ratio_correction) \
1564+
.scale(width * 0.5, height * 0.5) \
15801565
.rotate_deg(self.angle) \
1581-
.scale(1, 1 / self._aspect_ratio_correction) \
15821566
.translate(*center)
15831567

15841568
def get_path(self):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.