@@ -208,10 +208,10 @@ def as_artist(self, origin=(0, 0), **kwargs):
208208 angle = angle , ** mpl_kwargs )
209209
210210 def _update_from_mpl_selector (self , * args , ** kwargs ):
211- # _rect_properties replace _rect_bbox in matplotlib#19864
212- # "Note that if rotation != 0, ``xmin, ymin`` are interpreted as the
211+ # _rect_properties replace _rect_bbox in matplotlib#19864, unchanged in #20839.
212+ # "Note that if rotation != 0, ``xmin, ymin`` are always interpreted as the
213213 # lower corner, and ``xmax, ymax`` are calculated using only width and
214- # height assuming no rotation."
214+ # height assuming no rotation (as specified for ``selector.extents``) ."
215215
216216 xmin , xmax , ymin , ymax = self ._mpl_selector .extents
217217 self .width = xmax - xmin
@@ -222,7 +222,7 @@ def _update_from_mpl_selector(self, *args, **kwargs):
222222 else :
223223 self .center = PixCoord (x = 0.5 * (xmin + xmax ), y = 0.5 * (ymin + ymax ))
224224 rotation = 0
225- self .angle = rotation * u .radian
225+ self .angle = rotation * u .deg
226226
227227 if getattr (self , '_mpl_selector_callback' , None ) is not None :
228228 self ._mpl_selector_callback (self )
@@ -270,14 +270,14 @@ def as_mpl_selector(self, ax, active=True, sync=True, callback=None,
270270 ``selector.set_active(True)`` or ``selector.set_active(False)``.
271271 """
272272 from matplotlib .widgets import RectangleSelector
273-
274- from regions ._utils .optional_deps import MPL_VERSION
273+ from regions ._utils .optional_deps import MPL_VERSION , MPL_VER_STR
275274
276275 if hasattr (self , '_mpl_selector' ):
277276 raise AttributeError ('Cannot attach more than one selector to a region.' )
278277
279278 if self .angle .value != 0 and not hasattr (RectangleSelector , 'rotation' ):
280- raise NotImplementedError ('Cannot create matplotlib selector for rotated rectangle.' )
279+ raise NotImplementedError ('Creating selectors for rotated shapes is not '
280+ f'yet supported with matplotlib { MPL_VER_STR } .' )
281281
282282 if sync :
283283 sync_callback = self ._update_from_mpl_selector
@@ -298,12 +298,12 @@ def sync_callback(*args, **kwargs):
298298
299299 self ._mpl_selector = RectangleSelector (ax , sync_callback , interactive = True , ** kwargs )
300300
301- xy0 = [self .center . x - self . width / 2 , self . center . y - self .height / 2 ]
302- self ._mpl_selector .extents = (xy0 [0 ], self .center .x + self . width / 2 ,
303- xy0 [1 ], self .center .y + self . height / 2 )
301+ dxy = [self .width / 2 , self .height / 2 ]
302+ self ._mpl_selector .extents = (self . center . x - dxy [0 ], self .center .x + dxy [ 0 ] ,
303+ self . center . y - dxy [1 ], self .center .y + dxy [ 1 ] )
304304
305305 if self .angle .value != 0 :
306- self ._mpl_selector .rotation = self .angle .to_value ('radian ' )
306+ self ._mpl_selector .rotation = self .angle .to_value ('deg ' )
307307
308308 self ._mpl_selector .set_active (active )
309309 self ._mpl_selector_callback = callback
0 commit comments