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

Skip to content

Commit ca2abb3

Browse files
committed
Allow Rectangle and Ellipse selectors to be rotated
1 parent 876415d commit ca2abb3

File tree

3 files changed

+180
-72
lines changed

3 files changed

+180
-72
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Rotating selectors
2+
------------------
3+
4+
The `~matplotlib.widgets.RectangleSelector` and
5+
`~matplotlib.widgets.EllipseSelector` can now be rotated by pressing the 'r' key,
6+
and dragging one of their control points. The rotation is done about the first
7+
vertex placed when drawing the selector.

lib/matplotlib/tests/test_widgets.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,31 @@ def onselect(epress, erelease):
189189
tool._corner_handles.artist.get_markeredgecolor(), 'b')
190190

191191

192+
def test_rectangle_rotate():
193+
ax = get_ax()
194+
195+
def onselect(epress, erelease):
196+
pass
197+
198+
tool = widgets.RectangleSelector(ax, onselect=onselect, interactive=True)
199+
# Draw rectangle
200+
do_event(tool, 'press', xdata=100, ydata=100)
201+
do_event(tool, 'onmove', xdata=130, ydata=140)
202+
do_event(tool, 'release', xdata=130, ydata=140)
203+
assert tool.extents == (100, 130, 100, 140)
204+
205+
# Rotate by 45 degrees anticlockwise
206+
do_event(tool, 'press', xdata=130, ydata=140, key='r')
207+
do_event(tool, 'onmove', xdata=100, ydata=150, key='r')
208+
do_event(tool, 'release', xdata=100, ydata=200, key='r')
209+
# Extents shouldn't change (as shape of rectangle hasn't changed)
210+
assert tool.extents == (100, 130, 100, 140)
211+
# Corners should move
212+
# The third corner is at (100, 150), as the diagonal of the rectangle has
213+
# length 50
214+
assert tool.corners == ((100, 124, 100, 76), (100, 118, 150, 132))
215+
216+
192217
def check_span(*args, **kwargs):
193218
ax = get_ax()
194219

0 commit comments

Comments
 (0)