@@ -1801,7 +1801,7 @@ def _update(self):
18011801class _SelectorWidget (AxesWidget ):
18021802
18031803 def __init__ (self , ax , onselect , useblit = False , button = None ,
1804- state_modifier_keys = None ):
1804+ state_modifier_keys = None , use_data_coordinates = False ):
18051805 super ().__init__ (ax )
18061806
18071807 self .visible = True
@@ -1811,9 +1811,9 @@ def __init__(self, ax, onselect, useblit=False, button=None,
18111811
18121812 self ._state_modifier_keys = dict (move = ' ' , clear = 'escape' ,
18131813 square = 'shift' , center = 'control' ,
1814- data_coordinates = 'd' ,
18151814 rotate = 'r' )
18161815 self ._state_modifier_keys .update (state_modifier_keys or {})
1816+ self ._use_data_coordinates = use_data_coordinates
18171817
18181818 self .background = None
18191819
@@ -1999,17 +1999,15 @@ def on_key_press(self, event):
19991999 return
20002000 for (state , modifier ) in self ._state_modifier_keys .items ():
20012001 if modifier in key .split ('+' ):
2002- # 'rotate' and 'data_coordinates' are changing _state on
2003- # press and are not removed from _state when releasing
2004- if state in [ 'rotate' , 'data_coordinates' ] :
2002+ # 'rotate' is changing _state on press and is not removed
2003+ # from _state when releasing
2004+ if state == 'rotate' :
20052005 if state in self ._state :
20062006 self ._state .discard (state )
20072007 else :
20082008 self ._state .add (state )
20092009 else :
20102010 self ._state .add (state )
2011- if 'data_coordinates' in state :
2012- self ._set_aspect_ratio_correction ()
20132011 self ._on_key_press (event )
20142012
20152013 def _on_key_press (self , event ):
@@ -2019,12 +2017,10 @@ def on_key_release(self, event):
20192017 """Key release event handler and validator."""
20202018 if self .active :
20212019 key = event .key or ''
2022- key = key .replace ('ctrl' , 'control' )
20232020 for (state , modifier ) in self ._state_modifier_keys .items ():
2024- # 'rotate' and 'data_coordinates' are changing _state on
2025- # press and are not removed from _state when releasing
2026- if (modifier in key .split ('+' ) and
2027- state not in ['rotate' , 'data_coordinates' ]):
2021+ # 'rotate' is changing _state on press and is not removed
2022+ # from _state when releasing
2023+ if modifier in key .split ('+' ) and state != 'rotate' :
20282024 self ._state .discard (state )
20292025 self ._on_key_release (event )
20302026
@@ -2236,7 +2232,6 @@ def __init__(self, ax, onselect, direction, minspan=0, useblit=False,
22362232 state_modifier_keys = dict (clear = 'escape' ,
22372233 square = 'not-applicable' ,
22382234 center = 'not-applicable' ,
2239- data_coordinates = 'not-applicable' ,
22402235 rotate = 'not-applicable' )
22412236 super ().__init__ (ax , onselect , useblit = useblit , button = button ,
22422237 state_modifier_keys = state_modifier_keys )
@@ -2811,13 +2806,11 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
28112806 - "clear": Clear the current shape, default: "escape".
28122807 - "square": Make the shape square, default: "shift".
28132808 - "center": change the shape around its center, default: "ctrl".
2814- - "data_coordinates": define if data or figure coordinates should be
2815- used to define the square shape, default: "d"
28162809 - "rotate": Rotate the shape around its center, default: "r".
28172810
28182811 "square" and "center" can be combined. The square shape can be defined
2819- in data or figure coordinates as determined by the ``data_coordinates``
2820- modifier, which can be enable and disable by pressing the 'd' key .
2812+ in data or figure coordinates as determined by the
2813+ ``use_data_coordinates`` argument specified when creating the selector .
28212814
28222815 drag_from_anywhere : bool, default: False
28232816 If `True`, the widget can be moved by clicking anywhere within
@@ -2827,6 +2820,10 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
28272820 If `True`, the event triggered outside the span selector will be
28282821 ignored.
28292822
2823+ use_data_coordinates : bool, default: False
2824+ If `True`, the "square" shape of the selector is defined in
2825+ data coordinates instead of figure coordinates.
2826+
28302827 """
28312828
28322829
@@ -2871,9 +2868,11 @@ def __init__(self, ax, onselect, drawtype='box',
28712868 lineprops = None , props = None , spancoords = 'data' ,
28722869 button = None , grab_range = 10 , handle_props = None ,
28732870 interactive = False , state_modifier_keys = None ,
2874- drag_from_anywhere = False , ignore_event_outside = False ):
2871+ drag_from_anywhere = False , ignore_event_outside = False ,
2872+ use_data_coordinates = False ):
28752873 super ().__init__ (ax , onselect , useblit = useblit , button = button ,
2876- state_modifier_keys = state_modifier_keys )
2874+ state_modifier_keys = state_modifier_keys ,
2875+ use_data_coordinates = use_data_coordinates )
28772876
28782877 self .visible = True
28792878 self ._interactive = interactive
@@ -3076,7 +3075,7 @@ def _onmove(self, event):
30763075 # refmax is used when moving the corner handle with the square state
30773076 # and is the maximum between refx and refy
30783077 refmax = None
3079- if 'data_coordinates' in state :
3078+ if self . _use_data_coordinates :
30803079 refx , refy = dx , dy
30813080 else :
30823081 # Add 1e-6 to avoid divided by zero error
@@ -3213,7 +3212,7 @@ def _set_aspect_ratio_correction(self):
32133212 return
32143213
32153214 self ._selection_artist ._aspect_ratio_correction = aspect_ratio
3216- if 'data_coordinates' in self ._state :
3215+ if self ._use_data_coordinates :
32173216 self ._aspect_ratio_correction = 1
32183217 else :
32193218 self ._aspect_ratio_correction = aspect_ratio
@@ -3581,7 +3580,6 @@ def __init__(self, ax, onselect, useblit=False,
35813580 move_all = 'shift' , move = 'not-applicable' ,
35823581 square = 'not-applicable' ,
35833582 center = 'not-applicable' ,
3584- data_coordinates = 'not-applicable' ,
35853583 rotate = 'not-applicable' )
35863584 super ().__init__ (ax , onselect , useblit = useblit ,
35873585 state_modifier_keys = state_modifier_keys )
0 commit comments