@@ -205,10 +205,10 @@ def as_artist(self, origin=(0, 0), **kwargs):
205205 angle = angle , ** mpl_kwargs )
206206
207207 def _update_from_mpl_selector (self , * args , ** kwargs ):
208- # _rect_properties replace _rect_bbox in matplotlib#19864
209- # "Note that if rotation != 0, ``xmin, ymin`` are interpreted as the
208+ # _rect_properties replace _rect_bbox in matplotlib#19864, unchanged in #20839.
209+ # "Note that if rotation != 0, ``xmin, ymin`` are always interpreted as the
210210 # lower corner, and ``xmax, ymax`` are calculated using only width and
211- # height assuming no rotation."
211+ # height assuming no rotation (as specified for ``selector.extents``) ."
212212
213213 xmin , xmax , ymin , ymax = self ._mpl_selector .extents
214214 self .width = xmax - xmin
@@ -219,7 +219,7 @@ def _update_from_mpl_selector(self, *args, **kwargs):
219219 else :
220220 self .center = PixCoord (x = 0.5 * (xmin + xmax ), y = 0.5 * (ymin + ymax ))
221221 rotation = 0
222- self .angle = rotation * u .radian
222+ self .angle = rotation * u .deg
223223
224224 if getattr (self , '_mpl_selector_callback' , None ) is not None :
225225 self ._mpl_selector_callback (self )
@@ -267,13 +267,14 @@ def as_mpl_selector(self, ax, active=True, sync=True, callback=None,
267267 ``selector.set_active(True)`` or ``selector.set_active(False)``.
268268 """
269269 from matplotlib .widgets import RectangleSelector
270- from .._utils .optional_deps import MPL_VERSION
270+ from .._utils .optional_deps import MPL_VERSION , MPL_VER_STR
271271
272272 if hasattr (self , '_mpl_selector' ):
273273 raise AttributeError ('Cannot attach more than one selector to a region.' )
274274
275275 if self .angle .value != 0 and not hasattr (RectangleSelector , 'rotation' ):
276- raise NotImplementedError ('Cannot create matplotlib selector for rotated rectangle.' )
276+ raise NotImplementedError ('Creating selectors for rotated shapes is not '
277+ f'yet supported with matplotlib { MPL_VER_STR } .' )
277278
278279 if sync :
279280 sync_callback = self ._update_from_mpl_selector
@@ -294,12 +295,12 @@ def sync_callback(*args, **kwargs):
294295
295296 self ._mpl_selector = RectangleSelector (ax , sync_callback , interactive = True , ** kwargs )
296297
297- xy0 = [self .center . x - self . width / 2 , self . center . y - self .height / 2 ]
298- self ._mpl_selector .extents = (xy0 [0 ], self .center .x + self . width / 2 ,
299- xy0 [1 ], self .center .y + self . height / 2 )
298+ dxy = [self .width / 2 , self .height / 2 ]
299+ self ._mpl_selector .extents = (self . center . x - dxy [0 ], self .center .x + dxy [ 0 ] ,
300+ self . center . y - dxy [1 ], self .center .y + dxy [ 1 ] )
300301
301302 if self .angle .value != 0 :
302- self ._mpl_selector .rotation = self .angle .to_value ('radian ' )
303+ self ._mpl_selector .rotation = self .angle .to_value ('deg ' )
303304
304305 self ._mpl_selector .set_active (active )
305306 self ._mpl_selector_callback = callback
0 commit comments