@@ -1801,7 +1801,7 @@ def _update(self):
1801
1801
class _SelectorWidget (AxesWidget ):
1802
1802
1803
1803
def __init__ (self , ax , onselect , useblit = False , button = None ,
1804
- state_modifier_keys = None ):
1804
+ state_modifier_keys = None , use_data_coordinates = False ):
1805
1805
super ().__init__ (ax )
1806
1806
1807
1807
self .visible = True
@@ -1811,9 +1811,9 @@ def __init__(self, ax, onselect, useblit=False, button=None,
1811
1811
1812
1812
self ._state_modifier_keys = dict (move = ' ' , clear = 'escape' ,
1813
1813
square = 'shift' , center = 'control' ,
1814
- data_coordinates = 'd' ,
1815
1814
rotate = 'r' )
1816
1815
self ._state_modifier_keys .update (state_modifier_keys or {})
1816
+ self ._use_data_coordinates = use_data_coordinates
1817
1817
1818
1818
self .background = None
1819
1819
@@ -1999,17 +1999,15 @@ def on_key_press(self, event):
1999
1999
return
2000
2000
for (state , modifier ) in self ._state_modifier_keys .items ():
2001
2001
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' :
2005
2005
if state in self ._state :
2006
2006
self ._state .discard (state )
2007
2007
else :
2008
2008
self ._state .add (state )
2009
2009
else :
2010
2010
self ._state .add (state )
2011
- if 'data_coordinates' in state :
2012
- self ._set_aspect_ratio_correction ()
2013
2011
self ._on_key_press (event )
2014
2012
2015
2013
def _on_key_press (self , event ):
@@ -2021,10 +2019,9 @@ def on_key_release(self, event):
2021
2019
key = event .key or ''
2022
2020
key = key .replace ('ctrl' , 'control' )
2023
2021
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' ]):
2022
+ # 'rotate' is changing _state on press and is not removed
2023
+ # from _state when releasing
2024
+ if modifier in key .split ('+' ) and state != 'rotate' :
2028
2025
self ._state .discard (state )
2029
2026
self ._on_key_release (event )
2030
2027
@@ -2236,7 +2233,6 @@ def __init__(self, ax, onselect, direction, minspan=0, useblit=False,
2236
2233
state_modifier_keys = dict (clear = 'escape' ,
2237
2234
square = 'not-applicable' ,
2238
2235
center = 'not-applicable' ,
2239
- data_coordinates = 'not-applicable' ,
2240
2236
rotate = 'not-applicable' )
2241
2237
super ().__init__ (ax , onselect , useblit = useblit , button = button ,
2242
2238
state_modifier_keys = state_modifier_keys )
@@ -2811,13 +2807,11 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
2811
2807
- "clear": Clear the current shape, default: "escape".
2812
2808
- "square": Make the shape square, default: "shift".
2813
2809
- "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"
2816
2810
- "rotate": Rotate the shape around its center, default: "r".
2817
2811
2818
2812
"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 .
2813
+ in data or figure coordinates as determined by the
2814
+ ``use_data_coordinates`` argument specified when creating the selector .
2821
2815
2822
2816
drag_from_anywhere : bool, default: False
2823
2817
If `True`, the widget can be moved by clicking anywhere within
@@ -2827,6 +2821,10 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
2827
2821
If `True`, the event triggered outside the span selector will be
2828
2822
ignored.
2829
2823
2824
+ use_data_coordinates : bool, default: False
2825
+ If `True`, the "square" shape of the selector is defined in
2826
+ data coordinates instead of figure coordinates.
2827
+
2830
2828
"""
2831
2829
2832
2830
@@ -2871,9 +2869,11 @@ def __init__(self, ax, onselect, drawtype='box',
2871
2869
lineprops = None , props = None , spancoords = 'data' ,
2872
2870
button = None , grab_range = 10 , handle_props = None ,
2873
2871
interactive = False , state_modifier_keys = None ,
2874
- drag_from_anywhere = False , ignore_event_outside = False ):
2872
+ drag_from_anywhere = False , ignore_event_outside = False ,
2873
+ use_data_coordinates = False ):
2875
2874
super ().__init__ (ax , onselect , useblit = useblit , button = button ,
2876
- state_modifier_keys = state_modifier_keys )
2875
+ state_modifier_keys = state_modifier_keys ,
2876
+ use_data_coordinates = use_data_coordinates )
2877
2877
2878
2878
self .visible = True
2879
2879
self ._interactive = interactive
@@ -3076,7 +3076,7 @@ def _onmove(self, event):
3076
3076
# refmax is used when moving the corner handle with the square state
3077
3077
# and is the maximum between refx and refy
3078
3078
refmax = None
3079
- if 'data_coordinates' in state :
3079
+ if self . _use_data_coordinates :
3080
3080
refx , refy = dx , dy
3081
3081
else :
3082
3082
# Add 1e-6 to avoid divided by zero error
@@ -3213,7 +3213,7 @@ def _set_aspect_ratio_correction(self):
3213
3213
return
3214
3214
3215
3215
self ._selection_artist ._aspect_ratio_correction = aspect_ratio
3216
- if 'data_coordinates' in self ._state :
3216
+ if self ._use_data_coordinates :
3217
3217
self ._aspect_ratio_correction = 1
3218
3218
else :
3219
3219
self ._aspect_ratio_correction = aspect_ratio
@@ -3581,7 +3581,6 @@ def __init__(self, ax, onselect, useblit=False,
3581
3581
move_all = 'shift' , move = 'not-applicable' ,
3582
3582
square = 'not-applicable' ,
3583
3583
center = 'not-applicable' ,
3584
- data_coordinates = 'not-applicable' ,
3585
3584
rotate = 'not-applicable' )
3586
3585
super ().__init__ (ax , onselect , useblit = useblit ,
3587
3586
state_modifier_keys = state_modifier_keys )
0 commit comments