diff --git a/lib/matplotlib/tests/test_widgets.py b/lib/matplotlib/tests/test_widgets.py index 1986cd23f160..7220e269060d 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -452,6 +452,29 @@ def onselect(epress, erelease): tool._selection_artist.rotation_point = 'unvalid_value' +def test_rectangle_rotate_aspect_ratio(): + _, ax = plt.subplots() + ax.plot([1, 2, 3], [10, 20, 30]) + + def onselect(epress, erelease): + pass + + tool = widgets.RectangleSelector(ax, onselect=onselect, interactive=True) + + # Draw rectangle + do_event(tool, 'press', xdata=1, ydata=10) + do_event(tool, 'onmove', xdata=1.5, ydata=14) + do_event(tool, 'release', xdata=1.5, ydata=14) + assert tool.extents == (1.0, 1.5, 10.0, 14.0) + + # Rotate clockwise using bottom-right corner + do_event(tool, 'on_key_press', key='r') + do_event(tool, 'press', xdata=1.5, ydata=10) + do_event(tool, 'onmove', xdata=1.4, ydata=8.7) + do_event(tool, 'release', xdata=1.4, ydata=8.7) + assert_allclose(tool.rotation, -27.8, rtol=0.1) + + def test_rectange_add_remove_set(): ax = get_ax() diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 9c9fad1a20d5..69b33477b120 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -3087,8 +3087,9 @@ def _onmove(self, event): a = np.array([eventpress.xdata, eventpress.ydata]) b = np.array(self.center) c = np.array([event.xdata, event.ydata]) - angle = (np.arctan2(c[1]-b[1], c[0]-b[0]) - - np.arctan2(a[1]-b[1], a[0]-b[0])) + ax_corr = self.ax._get_aspect_ratio() + angle = (np.arctan2((c[1]-b[1]) * ax_corr, c[0]-b[0]) - + np.arctan2((a[1]-b[1]) * ax_corr, a[0]-b[0])) self.rotation = np.rad2deg(self._rotation_on_press + angle) # resize an existing shape pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy