@@ -203,20 +203,20 @@ def as_artist(self, origin=(0, 0), **kwargs):
203203 angle = angle , ** mpl_kwargs )
204204
205205 def _update_from_mpl_selector (self , * args , ** kwargs ):
206- # _rect_properties replace _rect_bbox in matplotlib#19864
207- # "Note that if rotation != 0, ``xmin, ymin`` are interpreted as the
206+ # _rect_properties replace _rect_bbox in matplotlib#19864, unchanged in #20839.
207+ # "Note that if rotation != 0, ``xmin, ymin`` are always interpreted as the
208208 # lower corner, and ``xmax, ymax`` are calculated using only width and
209- # height assuming no rotation."
209+ # height assuming no rotation (as specified for ``selector.extents``) ."
210210
211211 self .center = PixCoord (* self ._mpl_selector .center )
212- if hasattr (self ._mpl_selector , '_rotation' ):
213- x0 , y0 , self .width , self .height , rotation = self ._mpl_selector ._rect_properties
212+ xmin , xmax , ymin , ymax = self ._mpl_selector .extents
213+ self .width = 2 * (self .center .x - xmin )
214+ self .height = 2 * (self .center .y - ymin )
215+ if hasattr (self ._mpl_selector , 'rotation' ):
216+ rotation = self ._mpl_selector .rotation
214217 else :
215- xmin , xmax , ymin , ymax = self ._mpl_selector .extents
216- self .width = 2 * (self .center .x - xmin )
217- self .height = 2 * (self .center .y - ymin )
218218 rotation = 0
219- self .angle = rotation * u .radian
219+ self .angle = rotation * u .deg
220220
221221 if getattr (self , '_mpl_selector_callback' , None ) is not None :
222222 self ._mpl_selector_callback (self )
@@ -260,13 +260,17 @@ def as_mpl_selector(self, ax, active=True, sync=True, callback=None,
260260 ``selector.set_active(True)`` or ``selector.set_active(False)``.
261261 """
262262 from matplotlib .widgets import RectangleSelector
263+ import matplotlib ._version
264+ _mpl_version = getattr (matplotlib ._version , 'version' , None )
265+ if _mpl_version is None :
266+ _mpl_version = matplotlib ._version .get_versions ()['version' ]
263267
264268 if hasattr (self , '_mpl_selector' ):
265- raise Exception ('Cannot attach more than one selector to a '
266- 'region.' )
269+ raise Exception ('Cannot attach more than one selector to a region.' )
267270
268- if self .angle .value != 0 and not hasattr (RectangleSelector , '_rotation' ):
269- raise NotImplementedError ('Cannot create matplotlib selector for rotated rectangle.' )
271+ if self .angle .value != 0 and not hasattr (RectangleSelector , 'rotation' ):
272+ raise NotImplementedError ('Creating selectors for rotated shapes is not '
273+ f'yet supported with matplotlib { _mpl_version } .' )
270274
271275 if sync :
272276 sync_callback = self ._update_from_mpl_selector
@@ -281,13 +285,12 @@ def sync_callback(*args, **kwargs):
281285 'linewidth' : self .visual .get ('linewidth' , 1 ),
282286 'linestyle' : self .visual .get ('linestyle' , 'solid' )})
283287
284- xy0 = [self .center . x - self . width / 2 , self . center . y - self .height / 2 ]
285- self ._mpl_selector .extents = (xy0 [0 ], self .center .x + self . width / 2 ,
286- xy0 [1 ], self .center .y + self . height / 2 )
288+ dxy = [self .width / 2 , self .height / 2 ]
289+ self ._mpl_selector .extents = (self . center . x - dxy [0 ], self .center .x + dxy [ 0 ] ,
290+ self . center . y - dxy [1 ], self .center .y + dxy [ 1 ] )
287291
288292 if self .angle .value != 0 :
289- self ._mpl_selector ._set_corner_width_rotation (xy0 , self .width , self .height ,
290- self .angle .to_value ('radian' ))
293+ self ._mpl_selector .rotation = self .angle .to_value ('deg' )
291294
292295 self ._mpl_selector .set_active (active )
293296 self ._mpl_selector_callback = callback
0 commit comments