Only allow rotations on equal-aspect Axes · matplotlib/matplotlib@7645b29 · GitHub
Skip to content

Commit 7645b29

Browse files
committed
Only allow rotations on equal-aspect Axes
1 parent fe4bda0 commit 7645b29

3 files changed

Lines changed: 47 additions & 9 deletions

File tree

doc/users/next_whats_new/selector_rotate.rst

Lines changed: 4 additions & 3 deletions

lib/matplotlib/tests/test_widgets.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,38 @@ def onselect(epress, erelease):
226226
assert tool.corners == ((100, 112, 100, 88), (100, 109, 125, 116))
227227

228228

229+
@pytest.mark.parametrize('selector_class', [widgets.RectangleSelector,
230+
widgets.EllipseSelector])
231+
def test_rotate_warning(selector_class):
232+
# Check that a warning is raised when trying to rotate on a
233+
# non-equal aspect Axes.
234+
ax = get_ax()
235+
236+
def onselect(epress, erelease):
237+
pass
238+
239+
tool = selector_class(ax, onselect=onselect, interactive=True)
240+
ax.set_aspect(2)
241+
242+
# Draw rectangle
243+
do_event(tool, 'press', xdata=100, ydata=100)
244+
do_event(tool, 'onmove', xdata=130, ydata=140)
245+
do_event(tool, 'release', xdata=130, ydata=140)
246+
old_corners = tool.corners
247+
248+
# Try to rotate
249+
do_event(tool, 'on_key_press', key='r')
250+
do_event(tool, 'press', xdata=130, ydata=140)
251+
# Check warning is raised
252+
with pytest.warns(UserWarning, match='Rotation is only implemented for '
253+
'equal-aspect Axes.'):
254+
do_event(tool, 'onmove', xdata=100, ydata=150)
255+
do_event(tool, 'release', xdata=100, ydata=200)
256+
do_event(tool, 'on_key_release', key='r')
257+
# Check that corners haven't moved
258+
assert tool.corners == old_corners
259+
260+
229261
def check_span(*args, **kwargs):
230262
ax = get_ax()
231263

lib/matplotlib/widgets.py

Lines changed: 11 additions & 6 deletions

0 commit comments

Comments
 (0)