
    h%R                    &   S r SSKJr  SSKrSSKrSSKJrJr  SSKJr  SSK	r
SSKrSSKJrJrJrJrJrJrJrJrJr  SSKJr  SS	KJrJrJr  SS
KJrJr   " S S5      r  " S S5      r! " S S\!5      r" " S S\"5      r# " S S\"5      r$ " S S\$5      r% " S S\$5      r&S r' " S S\"5      r( " S S\"5      r) " S S\"5      r* " S  S!\!5      r+ " S" S#\"5      r, " S$ S%\!5      r- " S& S'\"5      r. " S( S)\.5      r/ " S* S+5      r0 " S, S-5      r1S.r2\Rf                  " \2Ri                  S/S05      5       " S1 S2\.5      5       r5\Rf                  " \2Ri                  S/S35      5       " S4 S5\55      5       r6 " S6 S7\.5      r7 " S8 S9\.5      r8 " S: S;\"5      r9g)<a|  
GUI neutral widgets
===================

Widgets that are designed to work for any of the GUI backends.
All of these widgets require you to predefine an `~.axes.Axes`
instance and pass that as the first parameter.  Matplotlib doesn't try to
be too smart with respect to layout -- you will have to figure out how
wide and tall you want your Axes to be to accommodate your widget.
    )	ExitStackN)IntegralNumber)cycler   )	_api
_docstringbackend_toolscbookcollectionscolorstextticker
transforms)Line2D)	RectangleEllipsePolygon)TransformedPatchPathAffine2Dc                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)LockDraw   a  
Some widgets, like the cursor, draw onto the canvas, and this is not
desirable under all circumstances, like when the toolbar is in zoom-to-rect
mode and drawing a rectangle.  To avoid this, a widget can acquire a
canvas' lock with ``canvas.widgetlock(widget)`` before drawing on the
canvas; this will prevent other widgets from doing so at the same time (if
they also try to acquire the lock first).
c                     S U l         g N_ownerselfs    D/var/www/html/env/lib/python3.13/site-packages/matplotlib/widgets.py__init__LockDraw.__init__&   s	        c                 R    U R                  U5      (       d  [        S5      eXl        g)zReserve the lock for *o*.zalready lockedN	available
ValueErrorr   r   os     r    __call__LockDraw.__call__)   s"    ~~a  -..r#   c                 T    U R                  U5      (       d  [        S5      eSU l        g)zRelease the lock from *o*.zyou do not own this lockNr%   r(   s     r    releaseLockDraw.release/   s$    ~~a  788r#   c                 \    U R                  5       (       + =(       d    U R                  U5      $ )z+Return whether drawing is available to *o*.)lockedisownerr(   s     r    r&   LockDraw.available5   s    ;;= 3DLLO3r#   c                     U R                   UL $ )z"Return whether *o* owns this lock.r   r(   s     r    r1   LockDraw.isowner9   s    {{ar#   c                     U R                   SL$ )z6Return whether the lock is currently held by an owner.Nr   r   s    r    r0   LockDraw.locked=   s    {{$&&r#   r   N)__name__
__module____qualname____firstlineno____doc__r!   r*   r-   r&   r1   r0   __static_attributes__ r#   r    r   r      s%    4 'r#   r   c                   F    \ rS rSrSrSrSrSrS rS r	\
" \	\SS9rS rS	rg
)WidgetB   z.
Abstract base class for GUI neutral widgets.
Tc                     Xl         g)z!Set whether the widget is active.N_active)r   actives     r    
set_activeWidget.set_activeJ   s    r#   c                     U R                   $ )z!Get whether the widget is active.rB   r   s    r    
get_activeWidget.get_activeN   s    ||r#   zIs the widget active?)docc                 $    U R                   (       + $ )zq
Return whether *event* should be ignored.

This method should be called at the beginning of any event callback.
)rD   r   events     r    ignoreWidget.ignoreU   s     ;;r#   rB   N)r7   r8   r9   r:   r;   drawoneventsonrC   rE   rH   propertyrD   rN   r<   r=   r#   r    r?   r?   B   s8     FHG
 j*2IJFr#   r?   c                   B    \ rS rSrSrS r\" S 5      rS rS r	S r
Srg	)

AxesWidget^   a  
Widget connected to a single `~matplotlib.axes.Axes`.

To guarantee that the widget remains responsive and not garbage-collected,
a reference to the object should be maintained by the user.

This is necessary because the callback registry
maintains only weak-refs to the functions, which are member
functions of the widget.  If there are no references to the widget
object it may be garbage collected which will disconnect the callbacks.

Attributes
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
canvas : `~matplotlib.backend_bases.FigureCanvasBase`
    The parent figure canvas for the widget.
active : bool
    If False, the widget does not respond to events.
c                     Xl         / U l        g r   )ax_cids)r   rW   s     r    r!   AxesWidget.__init__t   s    
r#   c                 H    U R                   R                  SS9R                  $ )NTroot)rW   
get_figurecanvasr   s    r    <lambda>AxesWidget.<lambda>x   s    477#5#54#5#@#G#Gr#   c                 p    U R                   R                  X5      nU R                  R                  U5        g)z
Connect a callback function with an event.

This should be used in lieu of ``figure.canvas.mpl_connect`` since this
function stores callback ids for later clean up.
N)r^   mpl_connectrX   append)r   rM   callbackcids       r    connect_eventAxesWidget.connect_eventz   s*     kk%%e6

#r#   c                 `    U R                    H  nU R                  R                  U5        M      g)z-Disconnect all events created by this widget.N)rX   r^   mpl_disconnect)r   cs     r    disconnect_eventsAxesWidget.disconnect_events   s"    AKK&&q) r#   c                     UR                   U R                  L a  UR                  UR                  4$ U R                  R                  R                  5       R                  UR                  UR                  45      $ )z8Return *event*'s data coordinates in this widget's Axes.)	inaxesrW   xdataydata	transDatainverted	transformxyrL   s     r    _get_data_coordsAxesWidget._get_data_coords   s]     /4lldgg.Eekk* 	QWW&&//1;;UWWegg<NO	Qr#   )rX   rW   N)r7   r8   r9   r:   r;   r!   rR   r^   rf   rk   rv   r<   r=   r#   r    rT   rT   ^   s)    * GHF*
Qr#   rT   c                   Z   ^  \ rS rSrSr  SSS.U 4S jjjrS rS rS rS	 r	S
 r
SrU =r$ )Button   a\  
A GUI neutral button.

For the button to remain responsive you must keep a reference to it.
Call `.on_clicked` to connect to the button.

Attributes
----------
ax
    The `~.axes.Axes` the button renders into.
label
    A `.Text` instance.
color
    The color of the button when not hovering.
hovercolor
    The color of the button when hovering.
T)useblitc          	      V  > [         TU ]  U5        Ub  UR                  U5        UR                  SSUSSUR                  S9U l        U=(       a    U R                  R                  U l        [        R                  " S/S9U l        U R                  SU R                  5        U R                  SU R                  5        U R                  S	U R                  5        UR!                  S
5        UR#                  U5        UR%                  / 5        UR'                  / 5        X@l        XPl        g)au  
Parameters
----------
ax : `~matplotlib.axes.Axes`
    The `~.axes.Axes` instance the button will be placed into.
label : str
    The button text.
image : array-like or PIL Image
    The image to place in the button, if not *None*.  The parameter is
    directly forwarded to `~.axes.Axes.imshow`.
color : :mpltype:`color`
    The color of the button when not activated.
hovercolor : :mpltype:`color`
    The color of the button when the mouse is over it.
useblit : bool, default: True
    Use blitting for faster drawing if supported by the backend.
    See the tutorial :ref:`blitting` for details.

    .. versionadded:: 3.7
N      ?center)verticalalignmenthorizontalalignmentrs   clickedsignalsbutton_press_eventbutton_release_eventmotion_notify_eventF)superr!   imshowr   	transAxeslabelr^   supports_blit_useblitr   CallbackRegistry
_observersrf   _click_release_motionset_navigateset_facecolor
set_xticks
set_ytickscolor
hovercolor)r   rW   r   imager   r   r{   	__class__s          r    r!   Button.__init__   s    , 	IIeWWS#u/719')||  5

  =DKK$=$=00)E/=14==A0$,,?


b
b
$r#   c                 .   U R                   (       a9  U R                  U5      (       d#  U R                  R                  U5      S   (       d  g UR                  R
                  U R                  :w  a&  UR                  R                  U R                  5        g g Nr   )rQ   rN   rW   containsr^   mouse_grabber
grab_mouserL   s     r    r   Button._click   sb    }}E 2 2$'':J:J5:QRS:T<<%%0LL##DGG, 1r#   c                 h   U R                  U5      (       d$  UR                  R                  U R                  :w  a  g UR                  R	                  U R                  5        U R
                  (       aA  U R                  R                  U5      S   (       a  U R                  R                  SU5        g g g )Nr   r   )	rN   r^   r   rW   release_mouserQ   r   r   processrL   s     r    r   Button._release   sw    ;;u!;!;tww!F""477+==TWW--e4Q7OO##Iu5 8=r#   c                 j   U R                  U5      (       a  g U R                  R                  U5      S   (       a  U R                  OU R                  n[
        R                  " X R                  R                  5       5      (       d  U R                  R                  U5        U R                  (       a  U R                  (       aU  U R                  R                  U R                  5        U R                  R                  U R                  R                  5        g U R                  R                  5         g g g r   )rN   rW   r   r   r   r   
same_colorget_facecolorr   rP   r   draw_artistr^   blitbboxdrawr   rM   rj   s      r    r   Button._motion   s    ;;u#ww//6q9DOOtzz  GG$9$9$;<<GG!!!${{==GG''0KK$$TWW\\2KK$$&  =r#   c                 D   ^ U R                   R                  SU4S j5      $ )z
Connect the callback function *func* to button click events.

Returns a connection id, which can be used to disconnect the callback.
r   c                    > T" U 5      $ r   r=   )rM   funcs    r    r_   #Button.on_clicked.<locals>.<lambda>   s	    Ur#   r   connectr   r   s    `r    
on_clickedButton.on_clicked   s     &&y2KLLr#   c                 :    U R                   R                  U5        g)z6Remove the callback function with connection id *cid*.Nr   
disconnectr   re   s     r    r   Button.disconnect       ""3'r#   )r   r   r   r   r   )Nz0.85z0.95)r7   r8   r9   r:   r;   r!   r   r   r   r   r   r<   __classcell__r   s   @r    ry   ry      sB    $ )-*0+%=A+% +%Z-6'M( (r#   ry   c                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )
SliderBase   z
The base class for constructing Slider widgets. Not intended for direct
usage.

For the slider to remain responsive you must maintain a reference to it.
c
                   > UR                   S:X  a  [        S5      e[        TU ]  U5        [        R
                  " SS/US9  X l        X0l        X@l        XPl	        X`l
        Xl        SU l        Xpl        US:X  a  UR                  XV45        UR                  n
OUR!                  XV45        UR"                  n
U
R%                  5       U l        [)        U R&                  [*        R,                  5      (       d5  [*        R,                  " 5       U l        U R&                  R/                  U
5        U R&                  R1                  S5        U R&                  R3                  S5        UR5                  5         UR7                  S5        U R9                  SU R:                  5        U R9                  S	U R:                  5        U(       a  U R9                  S
U R:                  5        [<        R>                  " S/S9U l         g )N3dz"Sliders cannot be added to 3D Axes
horizontalvertical)orientationFTr   r   r   changedr   )!namer'   r   r!   r   check_in_listr   	closedmin	closedmaxvalminvalmaxvalstepdrag_activevalfmtset_ylimyaxisset_xlimxaxisget_major_formatter_fmt
isinstancer   ScalarFormatterset_axisset_useOffsetset_useMathTextset_axis_offr   rf   _updater   r   r   )r   rW   r   r   r   r   r   r   draggingr   axisr   s              r    r!   SliderBase.__init__  sy   77d?ABBL*5;O&"" *$KK()88DKK()88D,,.	$))V%;%;<<..0DIIIt$		&		!!$'

/>14<<@4dllC00)Er#   c                    [        U R                  [        5      (       a@  U R                  [	        XR                  -
  U R                  -  5      U R                  -  -   nU$ U R                  bw  [
        R                  " U R                  5      nUR                  S:w  a  [        SUR                   35      eU[
        R                  " [
        R                  " X!-
  5      5         nU$ )z?Return *val* coerced to closest number in the ``valstep`` grid.r   z&valstep must have 1 dimension but has )r   r   r   r   roundnp
asanyarrayndimr'   argminabs)r   valr   s      r    _stepped_valueSliderBase._stepped_value*  s    dllF++;;C++-=>MNC 
 \\%mmDLL1G||q  <W\\NK  "))BFF7=$9:;C
r#   c                 :    U R                   R                  U5        g)z
Remove the observer with connection id *cid*.

Parameters
----------
cid : int
    Connection id of the observer to be removed.
Nr   r   s     r    r   SliderBase.disconnect8  s     	""3'r#   c                     [         R                  " U R                  U R                  :g  5      (       a  U R	                  U R                  5        gg)z&Reset the slider to the initial value.N)r   anyr   valinitset_valr   s    r    resetSliderBase.resetC  s3    66$((dll*++LL& ,r#   )
r   r   r   r   r   r   r   r   r   r   )r7   r8   r9   r:   r;   r!   r   r   r   r<   r   r   s   @r    r   r      s#    &FP	(' 'r#   r   c                   h   ^  \ rS rSrSrSSSSSSSSSSSSS	.U 4S
 jjrS rS rS rS r	S r
SrU =r$ )SlideriI  a  
A slider representing a floating point range.

Create a slider from *valmin* to *valmax* in Axes *ax*. For the slider to
remain responsive you must maintain a reference to it. Call
:meth:`on_changed` to connect to the slider event.

Attributes
----------
val : float
    Slider value.
r}   NTr   r	lightgrey)r   r   r   r   	slidermin	slidermaxr   r   r   	initcolortrack_colorhandle_stylec                  > [         TU ]  XXxX4XkU5	        U	b)  [        U	S5      (       d  [        S[	        U	5       S35      eU
b)  [        U
S5      (       d  [        S[	        U
5       S35      eXl        Xl        U R                  U5      nUc  UnXPl        XPl	        SSSS	.nUc  0 OUn0 UEUER                  5        VVs0 s H  u  nnS
U 3U_M     nnnUS:X  a  [        SSSUR                  US9U l        UR                  U R                  5        UR                  " X5SS40 UD6U l        UR#                  USSUS[%        U R                  5      S9U l        S/U//nO[        SSSUR                  US9U l        UR                  U R                  5        UR(                  " X5SS40 UD6U l        UR+                  USSUS[%        U R                  5      S9U l        U/S//nUR.                  " / UQSP70 UDSS0D6u  U l        US:X  aU  UR3                  SSX!R                  SSS9U l        UR3                  SSU R7                  U5      UR                  SSS9U l        OTUR3                  SSX!R                  SSS9U l        UR3                  SSU R7                  U5      UR                  SSS9U l        U R;                  U5        gs  snnf ) a	  
Parameters
----------
ax : Axes
    The Axes to put the slider in.

label : str
    Slider label.

valmin : float
    The minimum value of the slider.

valmax : float
    The maximum value of the slider.

valinit : float, default: 0.5
    The slider initial position.

valfmt : str, default: None
    %-format string used to format the slider value.  If None, a
    `.ScalarFormatter` is used instead.

closedmin : bool, default: True
    Whether the slider interval is closed on the bottom.

closedmax : bool, default: True
    Whether the slider interval is closed on the top.

slidermin : Slider, default: None
    Do not allow the current slider to have a value less than
    the value of the Slider *slidermin*.

slidermax : Slider, default: None
    Do not allow the current slider to have a value greater than
    the value of the Slider *slidermax*.

dragging : bool, default: True
    If True the slider can be dragged by the mouse.

valstep : float or array-like, default: None
    If a float, the slider will snap to multiples of *valstep*.
    If an array the slider will snap to the values in the array.

orientation : {'horizontal', 'vertical'}, default: 'horizontal'
    The orientation of the slider.

initcolor : :mpltype:`color`, default: 'r'
    The color of the line at the *valinit* position. Set to ``'none'``
    for no line.

track_color : :mpltype:`color`, default: 'lightgrey'
    The color of the background track. The track is accessible for
    further styling via the *track* attribute.

handle_style : dict
    Properties of the slider handle. Default values are

    ========= ===== ======= ========================================
    Key       Value Default Description
    ========= ===== ======= ========================================
    facecolor color 'white' The facecolor of the slider handle.
    edgecolor color '.75'   The edgecolor of the slider handle.
    size      int   10      The size of the slider handle in points.
    ========= ===== ======= ========================================

    Other values will be transformed as marker{foo} and passed to the
    `~.Line2D` constructor. e.g. ``handle_style = {'style'='x'}`` will
    result in ``markerstyle = 'x'``.

Notes
-----
Additional kwargs are passed on to ``self.poly`` which is the
`~matplotlib.patches.Rectangle` that draws the slider knob.  See the
`.Rectangle` documentation for valid property names (``facecolor``,
``edgecolor``, ``alpha``, etc.).
Nr   zArgument slidermin (z) has no 'val'zArgument slidermax (white.75
   	facecolor	edgecolorsizemarkerr         ?r   r}   r   rs   r  r        ?r   )r   lw	clip_pathr   r  r)   clip_onFRQ?bottomr~   rs   r   r   {Gztoprightleft)r   r!   hasattrr'   typer   r   _value_in_boundsr   r   itemsr   r   track	add_patchaxhspanpolyaxhliner   hlineaxvspanaxvlinevlineplot_handler   r   _formatvaltextr   )r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargsdefaultskvmarker_propshandleXYr   s                          r    r!   Slider.__init__W  s    b 	)7	D  E)B)B&tI&7~FH H E)B)B&tI&7~FH H""''0?G!(ubI)1r|(D8(D|(D(J(J(L
(L1fQCL!O(L 	 
 *$""a,,%DJ
 LL$

6CGGDI GQq.B4::.N $ PDJy)H"!R,,%DJ
 LL$

6CGGDIGQq.B4::.N $ PDJ 	C5)H 


 
 	
 *$dE\\3;5= ! ?DJ 773t||G/D-/\\5:7? # ADL
 Ull3;5< ! >DJ 774dll7.C-/\\5=7= # ?DL
 	Wm
s   ?Kc                    U R                  U5      nXR                  ::  a  U R                  (       d  gU R                  nO-XR                  :  a  U R                  (       d  gU R                  nU R
                  bA  XR
                  R                  ::  a(  U R                  (       d  gU R
                  R                  nU R                  bA  XR                  R                  :  a(  U R                  (       d  gU R                  R                  nU$ )z&Makes sure *val* is with given bounds.N)r   r   r   r   r   r   r   r   r   r   s     r    r  Slider._value_in_bounds  s    !!#&++>>++CKK>>++C>>%#1C1C*C>>..$$C>>%#1C1C*C>>..$$C
r#   c                    U R                  U5      (       d  UR                  S:w  a  gUR                  S:X  aO  U R                  R	                  U5      S   (       a,  SU l        UR                  R                  U R                  5        U R
                  (       d  gUR                  S:X  d3  UR                  S:X  aP  U R                  R	                  U5      S   (       d-  SU l        UR                  R                  U R                  5        gU R                  U5      u  p#U R                  U R                  S:X  a  UOU5      nUSU R                  4;  a  U R                  U5        gg	zUpdate the slider position.r   Nr   r   Tr   Fr   )rN   buttonr   rW   r   r   r^   r   r   rv   r  r   r   r   )r   rM   ro   rp   r   s        r    r   Slider._update  s   ;;u!2::--$''2B2B52I!2L#DLL##DGG,JJ0033DGG<L<LU<STU<V$DLL&&tww/,,U3##%%5E5BtTXX&&LL 'r#   c                     U R                   b  U R                   U-  $ U R                  R                  U R                  XR                  /5      u  p#nX0R                  R                  5       -   $ )Pretty-print *val*.r   r   format_ticksr   r   
get_offset)r   r   _ss       r    r#  Slider._format#  sV    ;;";;$$ii,,dkk3-LMGA!yy++---r#   c                    U R                   S:X  aR  U R                  R                  XR                  R                  5       -
  5        U R                  R                  U/5        OQU R                  R                  XR                  R                  5       -
  5        U R                  R                  U/5        U R                  R                  U R                  U5      5        U R                  (       a1  U R                  R                  SS9R                  R!                  5         Xl        U R$                  (       a  U R&                  R)                  SU5        gg)z?
Set slider value to *val*.

Parameters
----------
val : float
r   Tr[   r   N)r   r  
set_heightget_yr"  	set_ydata	set_widthget_x	set_xdatar$  set_textr#  rP   rW   r]   r^   	draw_idler   rQ   r   r   r-  s     r    r   Slider.set_val,  s     z)II  yy'8!89LL""C5)IIiioo&7 78LL""C5)dll3/0;;GGD)00::<==OO##Is3 r#   c                 D   ^ U R                   R                  SU4S j5      $ )a(  
Connect *func* as callback function to changes of the slider value.

Parameters
----------
func : callable
    Function to call when slider is changed.
    The function must accept a single float as its arguments.

Returns
-------
int
    Connection id (which can be used to disconnect *func*).
r   c                    > T" U 5      $ r   r=   r   r   s    r    r_   #Slider.on_changed.<locals>.<lambda>P  	    d3ir#   r   r   s    `r    
on_changedSlider.on_changedA       &&y2GHHr#   )r"  r   r  r   r  r   r   r  r   r   r$  r   )r7   r8   r9   r:   r;   r!   r  r   r#  r   rJ  r<   r   r   s   @r    r   r   I  sU     >A44$)S(t	Z Zx00.4*I Ir#   r   c            
          ^  \ rS rSrSrSSSSSSSSSS.	U 4S jjrS	 rS
 rS rS r	S r
S rS rS rS rS rS rSrU =r$ )RangeSlideriS  a  
A slider representing a range of floating point values. Defines the min and
max of the range via the *val* attribute as a tuple of (min, max).

Create a slider that defines a range contained within [*valmin*, *valmax*]
in Axes *ax*. For the slider to remain responsive you must maintain a
reference to it. Call :meth:`on_changed` to connect to the slider event.

Attributes
----------
val : tuple of float
    Slider value.
NTr   r   )	r   r   r   r   r   r   r   r   r   c       	         B  > [         TU ]  XXxX4XiU
5	        X44U l        Uc'  XC-
  n[        R                  " X?S-  -   X?S-  -   /5      nOU R                  U5      nXPl        XPl        SSSS.nUc  0 OUn0 UEUER                  5        VVs0 s H  u  nnSU 3U_M     nnnUS	:X  a_  [        S
SSUR                  US9U l
        UR                  U R                  5        U R                  R                  SS9nSUS   /nSUS   /nO^[        SSSUR                  US9U l
        UR                  U R                  5        U R                  R                  SS9nUS   S/nUS   S/n[        [        R                   " SS/5      40 UD6U l        U R$                  " U6   U R"                  R'                  U5        SU R"                  R)                  5       l        U R                  R                  U R"                  5        U R                  R-                  5         UR.                  " / UQSP70 UDSS0D6S   UR.                  " / UQSP70 UDSS0D6S   /U l        US	:X  aV  UR3                  SSUUR                  SSS9U l        UR3                  SSU R7                  U5      UR                  SSS9U l        OUUR3                  SSUUR                  SSS9U l        UR3                  SSU R7                  U5      UR                  SSS9U l        SU l        U R=                  U5        gs  snnf ) a+  
Parameters
----------
ax : Axes
    The Axes to put the slider in.

label : str
    Slider label.

valmin : float
    The minimum value of the slider.

valmax : float
    The maximum value of the slider.

valinit : tuple of float or None, default: None
    The initial positions of the slider. If None the initial positions
    will be at the 25th and 75th percentiles of the range.

valfmt : str, default: None
    %-format string used to format the slider values.  If None, a
    `.ScalarFormatter` is used instead.

closedmin : bool, default: True
    Whether the slider interval is closed on the bottom.

closedmax : bool, default: True
    Whether the slider interval is closed on the top.

dragging : bool, default: True
    If True the slider can be dragged by the mouse.

valstep : float, default: None
    If given, the slider will snap to multiples of *valstep*.

orientation : {'horizontal', 'vertical'}, default: 'horizontal'
    The orientation of the slider.

track_color : :mpltype:`color`, default: 'lightgrey'
    The color of the background track. The track is accessible for
    further styling via the *track* attribute.

handle_style : dict
    Properties of the slider handles. Default values are

    ========= ===== ======= =========================================
    Key       Value Default Description
    ========= ===== ======= =========================================
    facecolor color 'white' The facecolor of the slider handles.
    edgecolor color '.75'   The edgecolor of the slider handles.
    size      int   10      The size of the slider handles in points.
    ========= ===== ======= =========================================

    Other values will be transformed as marker{foo} and passed to the
    `~.Line2D` constructor. e.g. ``handle_style = {'style'='x'}`` will
    result in ``markerstyle = 'x'``.

Notes
-----
Additional kwargs are passed on to ``self.poly`` which is the
`~matplotlib.patches.Polygon` that draws the slider knob.  See the
`.Polygon` documentation for valid property names (``facecolor``,
``edgecolor``, ``alpha``, etc.).
Nr  r  r   r   r   r   r  r   r  r}      r  grid)whichr   r   r     d   r)   r  Fr  r  r~   r  r  r  r  r  )r   r!   r   r   arrayr  r   r  r   r   r  r  rW   get_yaxis_transformget_xaxis_transformr   zerosr  _update_selection_polyset_transformget_path_interpolation_steps_request_autoscale_viewr!  _handlesr   r   r#  r$  _active_handler   )r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r%  extentr&  r'  r(  r)  poly_transform
handleXY_1
handleXY_2r   s                          r    r!   RangeSlider.__init__b  s   d 	)7	D #?_Fhh$ 6 &$ 6 8 9G ++G4G!(ubI)1r|(D8(D|(D(J(J(L
(L1fQCL!O(L 	 
 *$""a,,%DJ
 LL$!WW88v8FNgaj)Jgaj)J"!R,,%DJ
 LL$!WW88v8FN!!*b)J!!*b)JBHHaV,77	##W-		/47		1$))$'')GG   	
  GG   	
 
 *$,,"*$, ! DJ 77W%,,"'$, # DL ,,"*$+ ! DJ 77W%,,"*$* # DL #Wg
s   Lc                     U R                   R                  nU R                  S:X  a"  SU4=US'   US'   SU4US'   SU4US'   SU4US'   g	US4=US'   US'   US4US'   US4US'   US4US'   g	)
z`
Update the vertices of the *self.poly* slider in-place
to cover the data range *vmin*, *vmax*.
r   r  r      r   r  rP     N)r  xyr   )r   vminvmaxvertss       r    rY  "RangeSlider._update_selection_poly  s     		z)"%t)+E!HuQxDyE!HDyE!HDyE!H"&)+E!HuQxSyE!HSyE!HSyE!Hr#   c                     XR                   ::  a,  U R                  (       d  U R                  S   $ U R                   nXR                  S   :  a  U R                  S   nU R                  U5      $ )z;Ensure the new min value is between valmin and self.val[1].r   r   )r   r   r   r   r   mins     r    _min_in_boundsRangeSlider._min_in_bounds/  sV    ++>>xx{"++C!((1+C""3''r#   c                     XR                   :  a,  U R                  (       d  U R                  S   $ U R                   nXR                  S   ::  a  U R                  S   nU R                  U5      $ )z;Ensure the new max value is between valmax and self.val[0].r   r   )r   r   r   r   r   maxs     r    _max_in_boundsRangeSlider._max_in_bounds:  sV    ++>>xx{"++C((1+((1+C""3''r#   c                 R    U R                  US   5      U R                  US   5      4$ )z#Clip min, max values to the bounds.r   r   )rp  ru  )r   valss     r    r  RangeSlider._value_in_boundsE  s+    ##DG,d.A.A$q'.JKKr#   c                    [         R                  " [         R                  " U R                  U-
  5      5      nUS:X  a#  U R	                  U5      nU R                  U5        O"U R                  U5      nU R                  U5        U R                  (       aJ  U R                  S:X  a  U R                  R                  U/5        gU R                  R                  U/5        gg)z2Update the slider value based on a given position.r   r   N)r   r   r   r   rp  set_minru  set_maxr_  r   r>  rA  )r   posidxr   s       r    _update_val_from_pos RangeSlider._update_val_from_posI  s    iitxx#~./!8%%c*CLL%%c*CLL:-##--se4##--se4	 r#   c           	      "   U R                  U5      (       d  UR                  S:w  a  gUR                  S:X  aO  U R                  R	                  U5      S   (       a,  SU l        UR                  R                  U R                  5        U R
                  (       d  gUR                  S:X  d3  UR                  S:X  aW  U R                  R	                  U5      S   (       d4  SU l        UR                  R                  U R                  5        SU l	        gU R                  U5      u  p#[        R                  " [        R                  " U R                  S:X  a0  U R                   Vs/ s H  oDR!                  5       S   U-
  PM     snO/U R                   Vs/ s H  oDR#                  5       S   U-
  PM     sn5      5      nU R                  U   nX`R                  La  X`l	        U R%                  U R                  S:X  a  U5        gU5        gs  snf s  snf r0  )rN   r1  r   rW   r   r   r^   r   r   r_  rv   r   r   r   r   r^  	get_xdata	get_ydatar  )r   rM   ro   rp   hhandle_indexhandles          r    r   RangeSlider._updateX  s   ;;u!2::--$''2B2B52I!2L#DLL##DGG,JJ0033DGG<L<LU<STU<V$DLL&&tww/"&D ,,U3yy</ 04}}=}![[]1%}=/3}}=}![[]1%}="? @ |, ,,,"(!!4+;+;|+K%WQVW >=s   !HHc                 ^   U R                   b)  SU R                   US   -   SU R                   US   -   S3$ U R                  R                  U R                  /UQU R                  P5      u  p#pBX0R                  R                  5       -  nX@R                  R                  5       -  nSU SU S3$ )r4  (r   z, r   )r5  )r   r   r8  s1s2s        r    r#  RangeSlider._formatz  s    ;;"t{{SV+,Bt{{SV/C.DAFF99110s0DKK0LA2 ))&&((B))&&((Brd"RD?"r#   c                 B    U R                  XR                  S   45        g)zP
Set the lower value of the slider to *min*.

Parameters
----------
min : float
r   Nr   r   rn  s     r    r{  RangeSlider.set_min  s     	c88A;'(r#   c                 D    U R                  U R                  S   U45        g)zP
Set the lower value of the slider to *max*.

Parameters
----------
max : float
r   Nr  rs  s     r    r|  RangeSlider.set_max  s     	dhhqk3'(r#   c                 >   [         R                  " U5      n[        R                  " SUS9  U R                  U R
                  4U l        U R                  U5      u  p#U R                  X#5        U R                  S:X  a?  U R                  S   R                  U/5        U R                  S   R                  U/5        O>U R                  S   R                  U/5        U R                  S   R                  U/5        U R                  R                  U R                  X#45      5        U R                   (       a1  U R"                  R%                  SS9R&                  R)                  5         X#4U l        U R*                  (       a  U R,                  R/                  SX#45        g	g	)
zV
Set slider value to *val*.

Parameters
----------
val : tuple or array-like of float
)rP  )r   r   r   r   Tr[   r   N)r   sortr   check_shaper   r   r   r  rY  r   r^  r>  rA  r$  rB  r#  rP   rW   r]   r^   rC  rQ   r   r   )r   r   ri  rj  s       r    r   RangeSlider.set_val  s:    ggcl3'KK-**3/
##D/z)MM!&&v.MM!&&v.MM!&&v.MM!&&v.dllD<89;;GGD)00::<<==OO##I|< r#   c                 D   ^ U R                   R                  SU4S j5      $ )a,  
Connect *func* as callback function to changes of the slider value.

Parameters
----------
func : callable
    Function to call when slider is changed. The function
    must accept a 2-tuple of floats as its argument.

Returns
-------
int
    Connection id (which can be used to disconnect *func*).
r   c                    > T" U 5      $ r   r=   rG  s    r    r_   (RangeSlider.on_changed.<locals>.<lambda>  rI  r#   r   r   s    `r    rJ  RangeSlider.on_changed  rL  r#   )	r_  r^  r   r   r  r  r   r   r$  )r7   r8   r9   r:   r;   r!   rY  rp  ru  r  r  r   r#  r{  r|  r   rJ  r<   r   r   s   @r    rN  rN  S  ss    *  v vp!*	(	(L5 XD#))=:I Ir#   rN  c                     [         R                  " U [        R                  5      n U (       a  [	        S0 U D6" 5       $ [
        R                  " 0 5      $ Nr=   )r   normalize_kwargsmtextTextr   	itertoolsrepeatpropss    r    _expand_text_propsr    s9    ""5%**5E %6?E??9+;+;B+??r#   c                      ^  \ rS rSrSrSSSSSS.U 4S jjjrS rS rS	 rS
 r	S r
SS jrS rS rS rS rS rS rSrU =r$ )CheckButtonsi  ai  
A GUI neutral set of check buttons.

For the check buttons to remain responsive you must keep a
reference to this object.

Connect to the CheckButtons with the `.on_clicked` method.

Attributes
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
labels : list of `~matplotlib.text.Text`
    The text label objects of the check buttons.
NT)r{   label_propsframe_propscheck_propsc                  > [         TU ]  U5        [        R                  " [        S4UXgS9  UR                  / 5        UR                  / 5        UR                  S5        Uc  S/[        U5      -  nU=(       a    U R                  R                  U l        SU l        [        R                  " SS[        U5      S-   5      SS n[        U5      n[!        XU5       V	V
Vs/ s H(  u  pnUR"                  " SX4UR$                  S	S
S.UD6PM*     snn
n	U l        [        R(                  " U R&                   Vs/ s H  oR+                  5       PM     sn5      S-  nUS-  SS.[,        R.                  " U[0        R2                  5      ESUR$                  S.EnUR5                  SUR7                  SS5      5        UR5                  SUR9                  SS5      5        UR:                  " S/[        U5      -  U40 UD6U l        SUS-  S.[,        R.                  " U[0        R2                  5      ESUR$                  U R                  S.EnUR5                  SUR9                  SS5      5        UR:                  " S/[        U5      -  U40 UD6U l        U RA                  U5        U RC                  SU RD                  5        U R                  (       a  U RC                  SU RF                  5        [,        RH                  " S/S9U l%        gs  snn
n	f s  snf )an  
Add check buttons to `~.axes.Axes` instance *ax*.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
labels : list of str
    The labels of the check buttons.
actives : list of bool, optional
    The initial check states of the buttons. The list must have the
    same length as *labels*. If not given, all buttons are unchecked.
useblit : bool, default: True
    Use blitting for faster drawing if supported by the backend.
    See the tutorial :ref:`blitting` for details.

    .. versionadded:: 3.7

label_props : dict, optional
    Dictionary of `.Text` properties to be used for the labels.

    .. versionadded:: 3.7
frame_props : dict, optional
    Dictionary of scatter `.Collection` properties to be used for the
    check button frame. Defaults (label font size / 2)**2 size, black
    edgecolor, no facecolor, and 1.0 linewidth.

    .. versionadded:: 3.7
check_props : dict, optional
    Dictionary of scatter `.Collection` properties to be used for the
    check button check. Defaults to (label font size / 2)**2 size,
    black color, and 1.0 linewidth.

    .. versionadded:: 3.7
N)r  r  r  Fr   r   rP  r  r  r~   rs   r   r   )r9  	linewidthr9  )r  rs   r  r   noner  black333333?)r  r9  rt   r  rs   animatedr   
draw_eventr   r   )&r   r!   r   check_isinstancedictr   r   r   lenr^   r   r   _backgroundr   linspacer  zipr   r   labelsrU  get_fontsizer   r  r   PathCollection
setdefaultgetpopscatter_frames_checks_init_statusrf   _clicked_clearr   r   )r   rW   r  activesr{   r  r  r  ysru   r   r  r   	text_sizer   s                 r    r!   CheckButtons.__init__  s   J 	tTl*5	P 	b
b
?gF+G=DKK$=$=[[As6{1}-a3(5
 $'r;#?	A $@% GGD! bll(.( $@	A
 HHdkkJkd//1kJKaO	 A
 $$[+2L2LM
 
 	{KOOGV,LM{KOOGW,MNzz4&3r7"2BF+FA
 $$[+2L2LM
 
 	{KOOGW,MNzz4&3r7"2BF+F 	'"/?==|T[[900)EIA
 Ks   /L6L
c                 "   U R                  U5      (       d  U R                  R                  5       (       a  gU R                  R                  U R                  R
                  5      U l        U R                  R                  U R                  5        gz,Internal event handler to clear the buttons.N)	rN   r^   	is_savingcopy_from_bboxrW   r   r  r   r  rL   s     r    r  CheckButtons._clear>  s[    ;;u!6!6!8!8;;55dggllCDLL)r#   c                    U R                  U5      (       d3  UR                  S:w  d#  U R                  R                  U5      S   (       d  g / U R                  R                  U5      S   S   Q[        U R                  5       VVs/ s H"  u  p#UR                  U5      S   (       d  M   UPM$     snnQnU(       a  U R                  R                  5       R                  U R                  R                  5       5      nU R                  XAR                  UR                  4XT   -
  S-  R                  S5      R                  5          5        g g s  snnf Nr   r   indrP  r  )rN   r1  rW   r   r  	enumerater  get_offset_transformrs   get_offsetsrE   rt   ru   sumr   r   rM   ir   idxscoordss         r    r  CheckButtons._clickedE  s   ;;u!2$'':J:J5:QRS:TS\\""5)!,U3S(5Q5GAu9Ma9Pa5QS \\668BB((*,FOO)FL8Q>CCBGNNPQS  R   E(Ec                     [         R                  " [        US9  [        U5      n[	        U R
                  U5       H  u  p#UR                  U5        M     gz
Set properties of the `.Text` labels.

.. versionadded:: 3.7

Parameters
----------
props : dict
    Dictionary of `.Text` properties to be used for the labels.
r  Nr   r  r  r  r  r  updater   r  r   props       r    set_label_propsCheckButtons.set_label_propsQ  A     	d%0"5)dkk51JDKK 2r#   c                     [         R                  " [        US9  SU;   a<  [        R                  " UR                  S5      [        U R                  5      5      US'   U R                  R                  U5        g)z
Set properties of the check button frames.

.. versionadded:: 3.7

Parameters
----------
props : dict
    Dictionary of `.Collection` properties to be used for the check
    button frames.
r  r9  sizesN)
r   r  r  r   broadcast_tor  r  r  r  r  r   r  s     r    set_frame_propsCheckButtons.set_frame_propsa  sR     	d%0%<__UYYs^S=MNE'NE"r#   c                 2   [         R                  " [        US9  SU;   a<  [        R                  " UR                  S5      [        U R                  5      5      US'   U R                  5       nU R                  R                  U5        U R                  U5        g)z
Set properties of the check button checks.

.. versionadded:: 3.7

Parameters
----------
props : dict
    Dictionary of `.Collection` properties to be used for the check
    button check.
r  r9  r  N)r   r  r  r   r  r  r  r  
get_statusr  r  r  )r   r  r  s      r    set_check_propsCheckButtons.set_check_propsr  sl     	d%0%<__UYYs^S=MNE'N//#E"'"r#   c                    U[        [        U R                  5      5      ;  a  [        SU 35      e[        R
                  " [        S4US9  [        R                  " S5      nU R                  R                  5       nUc  [        R                  " XA   U5      nU(       a  U R                  U   OUXA'   U R                  R                  U5        U R                  (       a  U R                  (       a  U R                   b%  U R"                  R%                  U R                   5        U R&                  R)                  U R                  5        U R"                  R+                  U R&                  R,                  5        OU R"                  R/                  5         U R0                  (       a8  U R2                  R5                  SU R                  U   R7                  5       5        gg)a  
Modify the state of a check button by index.

Callbacks will be triggered if :attr:`eventson` is True.

Parameters
----------
index : int
    Index of the check button to toggle.

state : bool, optional
    If a boolean value, set the state explicitly. If no value is
    provided, the state is toggled.

Raises
------
ValueError
    If *index* is invalid.
TypeError
    If *state* is not boolean.
zInvalid CheckButton index: Nstater  r   )ranger  r  r'   r   r  boolr   to_rgbar  r   r   _active_check_colorsr   rP   r   r  r^   restore_regionrW   r   r   r   r   rQ   r   r   get_text)r   indexr  	invisible
facecolorss        r    rE   CheckButtons.set_active  sH   , c$++.//:5'BCCtTl%8NN6*	\\//1
=%%j&7CE@ED55e<9
"":.;;}}##/KK..t/?/?@##DLL1  .  "==OO##It{{5/A/J/J/LM r#   c                 v   U R                   R                  5       U l        [        U R                  5      S:X  a.  [        R
                  " U R                  [        U5      SS9U l        U R                   R                  [        U R                  U5       VVs/ s H  u  p#U(       a  UOSPM     snn5        gs  snnf )z
Initialize properties to match active status.

The user may have passed custom colours in *check_props* to the
constructor, or to `.set_check_props`, so we need to modify the
visibility after getting whatever the user set.
r   r   r   r  N)r  r   r  r  r   r  r   r  )r   r  ecrD   s       r    r  CheckButtons._init_status  s     %)LL$>$>$@!t(()Q.(*		$2K2K25g,Q)HD%"""4#<#<gFHF Rv%FH	IHs   B5
c                    U R                   R                  S/[        U R                  5      -  5        [	        U S5      (       a7  U R
                   H'  u  pUR                  S5        UR                  S5        M)     U R                  (       a  U R                  R                  5         U R                  (       a  U R                  R                  SS5        gg)zUncheck all checkboxes.r  _linesFr   N)r  r   r  r  r  r  set_visiblerP   r^   r   rQ   r   r   )r   l1l2s      r    clearCheckButtons.clear  s     	""F8c$2K2K.L#LM4""++u%u% & ;;KK==OO##It4 r#   c           	          U R                   R                  5        Vs/ s H3  n[        R                  " U[        R                  " S5      5      (       + PM5     sn$ s  snf )zG
Return a list of the status (True/False) of all of the check buttons.
r  )r  get_facecolorsr   r   r  )r   r   s     r    r  CheckButtons.get_status  sO    
 "\\88:<:E %%eV^^F-CDD:< 	< <s   :Ac                     [        U R                  U R                  5       5       VVs/ s H  u  pU(       d  M  UR                  5       PM      snn$ s  snnf )z2Return a list of labels currently checked by user.)r  r  r  r  )r   lbox_checkeds      r    get_checked_labelsCheckButtons.get_checked_labels  sK     DKK!23 3 "0 

3  	   s
   AAc                 D   ^ U R                   R                  SU4S j5      $ )  
Connect the callback function *func* to button click events.

Parameters
----------
func : callable
    When the button is clicked, call *func* with button label.
    When all buttons are cleared, call *func* with None.
    The callback func must have the signature::

        def func(label: str | None) -> Any

    Return values may exist, but are ignored.

Returns
-------
A connection id, which can be used to disconnect the callback.
r   c                    > T" U 5      $ r   r=   r   r   s    r    r_   )CheckButtons.on_clicked.<locals>.<lambda>  s	    tDzr#   r   r   s    `r    r   CheckButtons.on_clicked  s    & &&y2IJJr#   c                 :    U R                   R                  U5        gz-Remove the observer with connection id *cid*.Nr   r   s     r    r   CheckButtons.disconnect  r   r#   )r  r  r  r  r   r   r  r   )r7   r8   r9   r:   r;   r!   r  r  r  r  r  rE   r  r  r  r  r   r   r<   r   r   s   @r    r  r    sm     [FD!t[F [Fz*
S #"#(,N\I 5"< K*( (r#   r  c                      ^  \ rS rSrSrSSSSSS.U 4S jjjr\S	 5       rS
 rS r	S r
S rS rS rS rS rS rS rS rS rSrU =r$ )TextBoxi  a  
A GUI neutral text input box.

For the text box to remain responsive you must keep a reference to it.

Call `.on_text_change` to be updated whenever the text changes.

Call `.on_submit` to be updated whenever the user hits enter or
leaves the text entry field.

Attributes
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
label : `~matplotlib.text.Text`

color : :mpltype:`color`
    The color of the text box when not hovering.
hovercolor : :mpltype:`color`
    The color of the text box when hovering.
z.951g{Gz?r  )r   r   	label_padtextalignmentc          
      >  > [         TU ]  U5        [        R                  " SSSS.US9U l        UR                  U* SX!R                  SSS9U l        U R                  R                  U R                  SX0R                  R                  SUS	S
9U l	        [        R                  " SS/S9U l        UR                  SSS	U/ / S9  SU l        UR                  SSSS	SS[         R"                  R%                  5       S9U l        U R)                  SU R*                  5        U R)                  SU R,                  5        U R)                  SU R.                  5        U R)                  SU R0                  5        U R)                  SU R2                  5        X@l        XPl        S	U l        g)a  
Parameters
----------
ax : `~matplotlib.axes.Axes`
    The `~.axes.Axes` instance the button will be placed into.
label : str
    Label for this text box.
initial : str
    Initial value in the text box.
color : :mpltype:`color`
    The color of the box.
hovercolor : :mpltype:`color`
    The color of the box when the mouse is over it.
label_pad : float
    The distance between the label and the right side of the textbox.
textalignment : {'left', 'center', 'right'}
    The horizontal location of the text.
皙?r}   gffffff?)r  r~   r  )r  r~   r  r  F)rs   r   r   
parse_mathchangesubmitr   r   r   )xlimylimnavigater  xticksyticksr   r'  r   )visibler   r	  rs   r   r   r   key_press_eventresize_eventN)r   r!   r   check_getitem_text_positionr   r   r   rW   	text_dispr   r   r   setcursor_indexvlinesmplr   IdentityTransformcursorrf   r   r   r   	_keypress_resizer   r   capturekeystrokes)	r   rW   r   initialr   r   r  r  r   s	           r    r!   TextBox.__init__  s   * 	"00S48') WWJUll&G  E

 g9J9J&M & 
  00(H9MN
feb 	 	"
 ii1aca*-..*J*J*L   N 	/=14==A0$,,?,dnn=>4<<8
$!&r#   c                 6    U R                   R                  5       $ r   )r-  r  r   s    r    r   TextBox.textP  s    ~~&&((r#   c                    U R                   R                  SS9nUR                  5       c  UR                  R	                  5         U R
                  R                  5       nUS U R                   nU R
                  R                  5       nU R
                  R                  U=(       d    S5        U R
                  R                  5       nUR                  UR                  :X  aE  U=R                  UR                  S-  -  sl
        U=R                  UR                  S-  -  sl        O7U(       d  UR                  Ul        OUR                  UR                  -   Ul        U R                   R#                  UR                  UR                  4UR                  UR                  4//SS9  U R
                  R                  U5        UR                  R	                  5         g )NTr[   ,rP  )segmentsr(  )rW   r]   _get_rendererr^   r   r-  r  r/  get_window_extentrB  y0y1heightx0x1widthr3  r.  )r   figr   	widthtextbb_textbb_widthtexts         r    _rendercursorTextBox._rendercursorT  s]    gg  d +&JJOO~~&&(+$++,	..224	 0S1~~779::#JJ,--11JJJ,--11J GJ l&8&88GJ

GJJ/'**gjj1IJK 	 	 	%

r#   c                     U R                  U5      (       a  g UR                  R                  U R                  :w  a  g UR                  R	                  U R                  5        g r   )rN   r^   r   rW   r   rL   s     r    r   TextBox._releasew  sC    ;;u<<%%0""477+r#   c                 p   U R                  U5      (       a  g U R                  (       Ga  UR                  nU R                  n[	        U5      S:X  a8  US U R
                   U-   X0R
                  S  -   nU =R
                  S-  sl        GOUS:X  a/  U R
                  [	        U5      :w  a  U =R
                  S-  sl        OUS:X  a&  U R
                  S:w  a  U =R
                  S-  sl        OUS:X  a  SU l        OUS:X  a  [	        U5      U l        OUS:X  aG  U R
                  S:w  a6  US U R
                  S-
   X0R
                  S  -   nU =R
                  S-  sl        OJUS:X  aD  U R
                  [	        U R                  5      :w  a!  US U R
                   X0R
                  S-   S  -   nU R                  R                  U5        U R                  5         U R                  (       aT  U R                  R                  S	U R                  5        US
;   a'  U R                  R                  SU R                  5        g g g g )Nr   r  r  r   homeend	backspacedeleter   )enterreturnr!  )rN   r6  keyr   r  r/  r-  rB  rJ  rQ   r   r   )r   rM   rU  r   s       r    r4  TextBox._keypress~  s   ;;u!!!))C99D3x1}/d//036../01!!Q&!$$D	1%%*%$$)%%*%$%!$'I!#$$) !7$"3"3a"78 !2!2!345D%%*%$$DII6 !3$"3"34 !2!2Q!6!789DNN##D) }}''$))<--OO++Hdii@ . 9 "r#   c                 N   [        U5      nU R                  U:X  a  g U R                  R                  U5        U R	                  5         U R
                  (       aM  U R                  R                  SU R                  5        U R                  R                  SU R                  5        g g )Nr   r!  )strr   r-  rB  rJ  rQ   r   r   )r   r   newvals      r    r   TextBox.set_val  st    S99'==OO##Hdii8OO##Hdii8 r#   c                 N   SU l         [        5       nUR                  U l        [	        U R
                  R                  SS9R                  R                  SS 5      nUb8  UR                  U 5        UR                  UR                  R                  U 5        g [        R                  " 5          UR                  [        R                   " [        R"                   Vs0 s H  o3R%                  S5      (       d  M  U/ _M     sn5      5        S S S 5        g s  snf ! , (       d  f       g = f)NTr[   toolmanagerzkeymap.)r6  r   close_on_stop_typinggetattrrW   r]   r^   managerkeypresslockrd   r-   r   'suppress_matplotlib_deprecation_warningenter_contextr1  
rc_contextrcParams
startswith)r   stackr\  r'  s       r    begin_typingTextBox.begin_typing  s    !% ${{GGD)0088-O" $$T*NN;33;;TB ==?##CNN$'LLLLqLL4KUQULL%N O @?L @?s$   +.DD6D=DD
D$c                    U R                   (       a  U R                  5         S U l        SnOSnSU l         U R                  R                  S5        U R                  R                  SS9R                  R                  5         U(       a9  U R                  (       a'  U R                  R                  SU R                  5        g g g )NTFr[   r!  )r6  r^  r3  r  rW   r]   r^   r   rQ   r   r   r   )r   notifysubmits     r    stop_typingTextBox.stop_typing  s    !!  "#'D L L!&&%,,113DMM OO##Hdii8 *<r#   c                    U R                  U5      (       a  g U R                  R                  U5      S   (       d  U R                  5         g U R                  (       d  g UR
                  R                  U R                  :w  a%  UR
                  R                  U R                  5        U R                  (       d  U R                  5         U R                  R                  UR                  5      U l        U R                  5         g r   )rN   rW   r   rl  rQ   r^   r   r   r6  rh  r-  _char_index_atrt   r/  rJ  rL   s     r    r   TextBox._click  s    ;;uww&q)}}<<%%0LL##DGG,%% NN99%''Br#   c                 $    U R                  5         g r   )rl  rL   s     r    r5  TextBox._resize  s    r#   c                    U R                  U5      (       a  g U R                  R                  U5      S   (       a  U R                  OU R                  n[
        R                  " X R                  R                  5       5      (       d_  U R                  R                  U5        U R                  (       a2  U R                  R                  SS9R                  R                  5         g g g )Nr   Tr[   )rN   rW   r   r   r   r   r   r   r   rP   r]   r^   r   r   s      r    r   TextBox._motion  s    ;;u#ww//6q9DOOtzz  GG$9$9$;<<GG!!!${{"""-4499;  =r#   c                 D   ^ U R                   R                  SU4S j5      $ )zs
When the text changes, call this *func* with event.

A connection id is returned which can be used to disconnect.
r   c                    > T" U 5      $ r   r=   r  s    r    r_   (TextBox.on_text_change.<locals>.<lambda>  	    d4jr#   r   r   s    `r    on_text_changeTextBox.on_text_change  s     &&x1HIIr#   c                 D   ^ U R                   R                  SU4S j5      $ )z
When the user hits enter or leaves the submission box, call this
*func* with event.

A connection id is returned which can be used to disconnect.
r!  c                    > T" U 5      $ r   r=   r  s    r    r_   #TextBox.on_submit.<locals>.<lambda>  rx  r#   r   r   s    `r    	on_submitTextBox.on_submit  s     &&x1HIIr#   c                 :    U R                   R                  U5        gr  r   r   s     r    r   TextBox.disconnect  r   r#   )
r   r^  r,  r6  r   r3  r/  r   r   r-  ) )r7   r8   r9   r:   r;   r!   rR   r   rJ  r   r4  r   rh  rl  r   r5  r   ry  r~  r   r<   r   r   s   @r    r  r    s}    ,:'%:' :'x ) )!F,"AH9O*9<JJ( (r#   r  c                      ^  \ rS rSrSrSSSSS.U 4S jjjrS rS rS	 rS
 r	\
S 5       r\R                  S 5       rS rS rS rS rSrU =r$ )RadioButtonsi  a  
A GUI neutral radio button.

For the buttons to remain responsive you must keep a reference to this
object.

Connect to the RadioButtons with the `.on_clicked` method.

Attributes
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
activecolor : :mpltype:`color`
    The color of the selected button.
labels : list of `.Text`
    The button labels.
value_selected : str
    The label text of the currently selected button.
index_selected : int
    The index of the selected button.
NT)r{   r  radio_propsc                  > [         TU ]  U5        [        R                  " [        S4UUS9  [
        R                  " U[        R                  5      nUb  SU;   a  [        R                  " S5        OSnX@l
        X0l        X#   U l        X0l        UR                  / 5        UR                  / 5        UR!                  S5        ["        R$                  " SS['        U5      S	-   5      SS
 nU=(       a    U R(                  R*                  U l        SU l        [1        U5      n[3        XU5       V	V
Vs/ s H(  u  pnUR4                  " SX4UR6                  SSS.UD6PM*     snn
n	U l        ["        R:                  " U R8                   Vs/ s H  oR=                  5       PM     sn5      S	-  nSUS	-  0UESUR6                  U R,                  S.EnUR?                  SURA                  SS5      5        UR?                  SURC                  SU5      5        URD                  " S/['        U5      -  U40 UD6U l#        U RF                  RI                  5       U l%        ['        U RJ                  5      S:X  a.  ["        RL                  " U RJ                  ['        U5      SS9U l%        U RF                  RO                  [Q        U RJ                  5       VVs/ s H  u  pX:X  a  UOSPM     snn5        U RS                  SU RT                  5        U R,                  (       a  U RS                  SU RV                  5        [
        RX                  " S/S9U l-        gs  snn
n	f s  snf s  snnf )aT  
Add radio buttons to an `~.axes.Axes`.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The Axes to add the buttons to.
labels : list of str
    The button labels.
active : int
    The index of the initially selected button.
activecolor : :mpltype:`color`
    The color of the selected button. The default is ``'blue'`` if not
    specified here or in *radio_props*.
useblit : bool, default: True
    Use blitting for faster drawing if supported by the backend.
    See the tutorial :ref:`blitting` for details.

    .. versionadded:: 3.7

label_props : dict or list of dict, optional
    Dictionary of `.Text` properties to be used for the labels.

    .. versionadded:: 3.7
radio_props : dict, optional
    Dictionary of scatter `.Collection` properties to be used for the
    radio buttons. Defaults to (label font size / 2)**2 size, black
    edgecolor, and *activecolor* facecolor (when active).

    .. note::
        If a facecolor is supplied in *radio_props*, it will override
        *activecolor*. This may be used to provide an active color per
        button.

    .. versionadded:: 3.7
N)r  r  r  zBoth the *activecolor* parameter and the *facecolor* key in the *radio_props* parameter has been specified. *activecolor* will be ignored.blueFr   r   rP  r  r  r  r~   r  r9  r)   r  r  r   r  r  r  r  r   r  r   r   ).r   r!   r   r  r  r   r  r   r  warn_external_activecolor_initial_activevalue_selectedindex_selectedr   r   r   r   r  r  r^   r   r   r  r  r  r   r   r  rU  r  r  r  r  r  _buttonsr   _active_colorsr  r   r  rf   r  r  r   r   )r   rW   r  rD   activecolorr{   r  r  r  ru   r   r  r   r  r  r   s                  r    r!   RadioButtons.__init__  s   L 	tTl*5	7 ,,[-8-G-GI"k)""56
 !K'%$n$
b
b
[[As6{Q/"5=DKK$=$=(5
 $'r;#?	A $@% GGD! bll(.( $@	A
 HHdkkJkd//1kJKaO	 A

 
 	{KOOGW,MN{*wD	F

C53r7?BF+F #mm99;t""#q("$))D,?,?V12#4D###,T-@-@#AC#A K[V3#AC	D 	/?==|T[[900)ECA
 K*Cs   //M
M	M
c                 "   U R                  U5      (       d  U R                  R                  5       (       a  gU R                  R                  U R                  R
                  5      U l        U R                  R                  U R                  5        gr  )	rN   r^   r  r  rW   r   r  r   r  rL   s     r    r  RadioButtons._clear  s[    ;;u!6!6!8!8;;55dggllCDMM*r#   c                    U R                  U5      (       d3  UR                  S:w  d#  U R                  R                  U5      S   (       d  g / U R                  R                  U5      S   S   Q[        U R                  5       VVs/ s H"  u  p#UR                  U5      S   (       d  M   UPM$     snnQnU(       a  U R                  R                  5       R                  U R                  R                  5       5      nU R                  XAR                  UR                  4XT   -
  S-  R                  S5      R                  5          5        g g s  snnf r  )rN   r1  rW   r   r  r  r  r  rs   r  rE   rt   ru   r  r   r  s         r    r  RadioButtons._clicked  s   ;;u!2$'':J:J5:QRS:TS]]##E*1-e4S(5Q5GAu9Ma9Pa5QS ]]779CC))+-FOO)FL8Q>CCBGNNPQS  Rr  c                     [         R                  " [        US9  [        U5      n[	        U R
                  U5       H  u  p#UR                  U5        M     gr  r  r  s       r    r  RadioButtons.set_label_props  r  r#   c                    [         R                  " [        US9  SU;   a<  [        R                  " UR                  S5      [        U R                  5      5      US'   U R                  R                  U5        U R                  R                  5       U l        [        U R                  5      S:X  a8  [        R                  " U R                  [        U R                  5      SS9U l        U R                  R                  [        U R                  U R                  5       VVs/ s H'  u  p#UR                  5       U R                   :X  a  UOSPM)     snn5        gs  snnf )	z
Set properties of the `.Text` labels.

.. versionadded:: 3.7

Parameters
----------
props : dict
    Dictionary of `.Collection` properties to be used for the radio
    buttons.
r  r9  r  r   r   r  r  N)r   r  r  r   r  r  r  r  r  r  r   r  r  r   r  r  r  )r   r  r   r  s       r    set_radio_propsRadioButtons.set_radio_props  s    	d%0%<__UYYs^S=MNE'NU#"mm99;t""#q("$))D,?,?,/,<1#FD##&)$++t7J7J&KM&K" !MMOt/B/BB[N&KM	NMs   .E
c                     U R                   $ r   )r  r   s    r    r  RadioButtons.activecolor  s       r#   c                 ^    [         R                  " US9  Xl        U R                  SU05        g )N)r  r  )r   _check_color_liker  r  )r   r  s     r    r  r    s)      [9'k;78r#   c                    U[        [        U R                  5      5      ;  a  [        SU 35      eU R                  U   R	                  5       U l        Xl        U R                  R                  5       n[        R                  " S5      USS& [        R                  " U R                  U   5      X!'   U R                  R                  U5        U R                  (       a  U R                  (       a  U R                  b%  U R                   R#                  U R                  5        U R$                  R'                  U R                  5        U R                   R)                  U R$                  R*                  5        OU R                   R-                  5         U R.                  (       a8  U R0                  R3                  SU R                  U   R	                  5       5        gg)z
Select button with number *index*.

Callbacks will be triggered if :attr:`eventson` is True.

Parameters
----------
index : int
    The index of the button to activate.

Raises
------
ValueError
    If the index is invalid.
zInvalid RadioButton index: r  Nr   )r  r  r  r'   r  r  r  r  r   r   r  r  r   rP   r   r  r^   r  rW   r   r   r   r   rQ   r   r   )r   r  button_facecolorss      r    rE   RadioButtons.set_active  sH     c$++.//:5'BCC"kk%099;# MM779%~~f5!#)>>$2E2Ee2L#M ##$56;;}}##/KK..t/?/?@##DMM2  .  "==OO##It{{5/A/J/J/LM r#   c                 :    U R                  U R                  5        g)z4Reset the active button to the initially active one.N)rE   r  r   s    r    r  RadioButtons.clear  s    ,,-r#   c                 :    U R                   R                  SU5      $ )r  r   r   r   s     r    r   RadioButtons.on_clicked  s    & &&y$77r#   c                 :    U R                   R                  U5        gr  r   r   s     r    r   RadioButtons.disconnect  r   r#   )
r  r  r  r  r  r   r   r  r  r  )r   N)r7   r8   r9   r:   r;   r!   r  r  r  r  rR   r  setterrE   r  r   r   r<   r   r   s   @r    r  r    s    ,fF4TfF fFP+
S N0 ! ! 9 9
#NJ.8*( (r#   r  c                   *    \ rS rSrSrS rS rS rSrg)SubplotTooli  z5
A tool to adjust the subplot params of a `.Figure`.
c                 j   X l         Xl        UR                  SSS9  UR                  S5        / U l        / SQn[        X2R                  [        U5      S-   5      5       Hl  u  pEUR                  S5        [        XTSS[        UR                  U5      S	9nUR                  U R                  5        U R                  R                  U5        Mn     UR                  S
   R!                  5         U R                  u  U l        U l        U l        U l        U l        U l        U R"                  U R$                  U R*                  U R,                  4 H
  nSUl        M     U R&                  U R(                  4 H
  nSUl        M     U R&                  U R"                  l        U R"                  U R&                  l        U R(                  U R$                  l        U R$                  U R(                  l        UR7                  / SQ5      n[9        US5      U l        U R:                  R=                  U R>                  5        g)z
Parameters
----------
targetfig : `~matplotlib.figure.Figure`
    The figure instance to adjust.
toolfig : `~matplotlib.figure.Figure`
    The figure instance to embed the subplot tool into.
皙?g?)r  r  z'Click on slider to adjust subplot param)r  r  r  r  wspacehspacer   Fr   )r   r  )g?r  r  g333333?ResetN) figure	targetfigsubplots_adjustsuptitle_slidersr  subplotsr  r   r   r_  subplotparsrJ  _on_slider_changedrc   axesremove
sliderleftsliderbottomsliderright	slidertopsliderwspacesliderhspacer   r   r   r   add_axesry   buttonresetr   	_on_reset)r   r  toolfignamesr   rW   sliderbaxs           r    r!   SubplotTool.__init__  s    "S4BCFE#3#3CJN#CDHDOOE"Ba$+I,A,A4$HJFd556MM  ( E 	R!15	/$+T-=t~		D-(9(9(($*;*;=F$F= ''8F$F 9 %)$4$4!%)__"&*nn##'#4#4 78!#w/##DNN3r#   c           	      .   U R                   R                  " S0 U R                   Vs0 s H(  nUR                  R	                  5       UR
                  _M*     snD6  U R                  (       a%  U R                   R                  R                  5         g g s  snf r  )	r  r  r  r   r  r   rP   r^   r   )r   r8  r  s      r    r  SubplotTool._on_slider_changed8  sw    && 	-!]],*6 ||$$&

2*,	- ;;NN!!&&( ,s   /Bc           
         [        5        nUR                  [        R                  " U SS95        U R                   H(  nUR                  [        R                  " USSS95        M*     U R                   H  nUR                  5         M     S S S 5        U R                  (       a  UR                  R                  5         U R                  S 5        g ! , (       d  f       NK= f)NF)rP   )rP   rQ   )
r   rc  r   _setattr_cmr  r   rP   r^   r   r  )r   rM   rg  r  s       r    r  SubplotTool._on_reset?  s    [E  1 1$u EF--##%%fUUKM ( -- (  ;;LL% [s   B C
C)
r  r  r  r  r  r  r  r  r  r  N)	r7   r8   r9   r:   r;   r!   r  r  r<   r=   r#   r    r  r    s    )4V)&r#   r  c                   D   ^  \ rS rSrSrSSSS.U 4S jjrS rS rS	rU =r	$ )
CursoriP  a  
A crosshair cursor that spans the Axes and moves with mouse cursor.

For the cursor to remain responsive you must keep a reference to it.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The `~.axes.Axes` to attach the cursor to.
horizOn : bool, default: True
    Whether to draw the horizontal line.
vertOn : bool, default: True
    Whether to draw the vertical line.
useblit : bool, default: False
    Use blitting for faster drawing if supported by the backend.
    See the tutorial :ref:`blitting` for details.

Other Parameters
----------------
**lineprops
    `.Line2D` properties that control the appearance of the lines.
    See also `~.Axes.axhline`.

Examples
--------
See :doc:`/gallery/widgets/cursor`.
TF)horizOnvertOnr{   c                  > [         TU ]  U5        U R                  SU R                  5        U R                  SU R                  5        SU l        X l        X0l        U=(       a    U R                  R                  U l
        U R                  (       a  SUS'   UR                  " UR                  5       S   4SS0UD6U l        UR                  " UR                  5       S   4SS0UD6U l        S U l        SU l        g )Nr   r  Tr  r   r(  F)r   r!   rf   onmover  r(  r  r  r^   r   r{   r  
get_yboundlinehr  
get_xboundlinev
background	needclear)r   rW   r  r  r{   	linepropsr   s         r    r!   Cursor.__init__l  s    0$++><4<4;;#<#<<<$(Ij!ZZ 2OEOYO
ZZ 2OEOYO
r#   c                     U R                  U5      (       d  U R                  R                  5       (       a  gU R                  (       a5  U R                  R	                  U R
                  R                  5      U l        gg)z+Internal event handler to clear the cursor.N)rN   r^   r  r{   r  rW   r   r  rL   s     r    r  Cursor.clear  sP    ;;u!6!6!8!8<<"kk88FDO r#   c                 :   U R                  U5      (       a  gU R                  R                  R                  U 5      (       d  gU R                  R                  U5      S   (       di  U R                  R                  S5        U R                  R                  S5        U R                  (       a!  U R                  R                  5         SU l	        gSU l	        U R                  U5      u  p#U R                  R                  X"45        U R                  R                  U R                  =(       a    U R                  5        U R                  R                  X345        U R                  R                  U R                  =(       a    U R                   5        U R                  (       a"  U R                  (       d  U R                   (       d  gU R"                  (       a  U R$                  b%  U R                  R'                  U R$                  5        U R                  R)                  U R                  5        U R                  R)                  U R                  5        U R                  R+                  U R                  R,                  5        gU R                  R/                  5         g)z?Internal event handler to draw the cursor when the mouse moves.Nr   FT)rN   r^   
widgetlockr&   rW   r   r  r  r  r  r   rv   rA  r(  r  r>  r  r{   r  r  r   r   r   rC  r   rM   ro   rp   s       r    r  Cursor.onmove  s   ;;u{{%%//55ww&q)JJ""5)JJ""5)~~  "!&,,U3

e^,

t||;<

e^,

t||<=$++<<***4??;GG

+GG

+KKTWW\\*KK!!#r#   )r  r  r  r  r  r{   r  r(  )
r7   r8   r9   r:   r;   r!   r  r  r<   r   r   s   @r    r  r  P  s+    6 '+4  (G$ $r#   r  c                   B    \ rS rSrSrSSSS.S jrS rS rS	 rS
 r	Sr
g)MultiCursori  a[  
Provide a vertical (default) and/or horizontal line cursor shared between
multiple Axes.

For the cursor to remain responsive you must keep a reference to it.

Parameters
----------
canvas : object
    This parameter is entirely unused and only kept for back-compatibility.

axes : list of `~matplotlib.axes.Axes`
    The `~.axes.Axes` to attach the cursor to.

useblit : bool, default: True
    Use blitting for faster drawing if supported by the backend.
    See the tutorial :ref:`blitting`
    for details.

horizOn : bool, default: False
    Whether to draw the horizontal line.

vertOn : bool, default: True
    Whether to draw the vertical line.

Other Parameters
----------------
**lineprops
    `.Line2D` properties that control the appearance of the lines.
    See also `~.Axes.axhline`.

Examples
--------
See :doc:`/gallery/widgets/multicursor`.
TF)r{   r  r  c                   Xl         X l        X@l        XPl        U Vs0 s H   nUR	                  SS9R
                  / S S._M"     snU l        US   R                  5       u  pUS   R                  5       u  pSX-   -  nSX-   -  nSU l	        U=(       a    [        S U R                   5       5      U l        U R                  (       a  SUS'   U Vs/ s H  nUR                  " U4SS	0UD6PM     snU l        U Vs/ s H  nUR                  " U4SS	0UD6PM     snU l        U R!                  5         g s  snf s  snf s  snf )
NTr[   )cidsr  r  r}   c              3   8   #    U  H  oR                   v   M     g 7fr   )r   ).0r^   s     r    	<genexpr>'MultiCursor.__init__.<locals>.<genexpr>  s     J7IV((7Is   r  r(  F)_canvasr  r  r  r]   r^   _canvas_infosget_xlimget_ylimr(  allr{   r  r0  r  hlinesr   )r   r^   r  r{   r  r  r  rW   xminxmaxyminymaxxmidymids                 r    r!   MultiCursor.__init__  s^    	 <@A;?R MMtM$++401;?A "X&&(
"X&&(
dk"dk" KJt7I7IJJ 	 <<$(Ij! "&'!%2 zz$CCC!%' "&'!%2 zz$CCC!%' 	-A"''s   'D2D7:D<c                     U R                   R                  5        H@  u  pUR                  SU R                  5      UR                  SU R                  5      /US'   MB     g)zConnect events.r   r  r  N)r  r  rb   r  r  )r   r^   infos      r    r   MultiCursor.connect  sQ     ..446LF""#8$++F""<<DL 7r#   c                     U R                   R                  5        H5  u  pUS    H  nUR                  U5        M     US   R                  5         M7     g)zDisconnect events.r  N)r  r  ri   r  )r   r^   r  re   s       r    r   MultiCursor.disconnect  sI     ..446LFF|%%c* $L  7r#   c                     U R                  U5      (       a  gU R                  (       af  U R                  R                  5        HG  u  p#X"R                  R
                  La  M  UR                  UR                  R                  5      US'   MI     gg)zClear the cursor.Nr  )rN   r{   r  r  r  r^   r  r   )r   rM   r^   r  s       r    r  MultiCursor.clear  so    ;;u<< $ 2 2 8 8 :
 !5!55%+%:%:6==;M;M%N\" !; r#   c                    U R                    Vs/ s H  o"R                  U5      S   (       d  M  UPM!     nnU R                  U5      (       d1  U(       a*  UR                  R                  R                  U 5      (       d  g [        R                  " U5      nUR                  UL a  UR                  UR                  4O>UR                  R                  5       R                  UR                  UR                  45      u  pEU R                    HC  nUR#                  XD45        UR%                  U R&                  =(       a    U R(                  5        ME     U R*                   HC  nUR-                  XU45        UR%                  U R&                  =(       a    U R.                  5        ME     U R&                  (       a"  U R(                  (       d  U R.                  (       d  g U R0                  (       a  U R2                  R5                  5        H%  u  pxUS   (       d  M  UR7                  US   5        M'     U R(                  (       a:  [9        U R                   U R                   5       H  u  p&UR;                  U5        M     U R.                  (       a:  [9        U R                   U R*                  5       H  u  p&UR;                  U5        M     U R2                   H  nUR=                  5         M     g U R2                   H  nUR?                  5         M     g s  snf )Nr   r  ) r  r   rN   r^   r  r&   r   _topmost_artistrn   ro   rp   rq   rr   rs   rt   ru   r0  rA  r  r(  r  r  r>  r  r{   r  r  r  r  r   r   rC  )	r   rM   rW   axsro   rp   liner^   r  s	            r    r  MultiCursor.onmove  s    II?IbU);A)>rI?;;uS0G0G0Q0QRV0W0W""3'6;llb6Hekk2\\224>>?QR 	KKDNNE>*T\\9dkk:   KKDNNE>*T\\:dll;   $++<< $ 2 2 8 8 :%%))$|*<= !; {{ #DIIt{{ ;HBNN4( !<|| #DIIt{{ ;HBNN4( !<,, - ,,  " -9 @s
   L	L	)	r  r  r  r  r  r{   r  r(  r0  N)r7   r8   r9   r:   r;   r!   r   r   r  r  r<   r=   r#   r    r  r    s,    "H 15eD  D!O#r#   r  c                      ^  \ rS rSr  S"U 4S jjrU 4S jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r\S 5       rS rS r S r!S r"S  r#S!r$U =r%$ )#_SelectorWidgeti,  c                   > [         TU ]  U5        SU l        Uc	  S U l        OX l        U=(       a    U R                  R
                  U l        U R                  5         [        SSSSSS9U l	        U R                  R                  U=(       d    0 5        X`l        S U l        [        U[        5      (       a	  U/U l        OX@l        S	U l        S U l        S U l        S U l        [)        5       U l        g )
NTc                      g r   r=   )argss    r    r_   *_SelectorWidget.__init__.<locals>.<lambda>4  s    $r#    escapeshiftcontrolr   )mover  squarer~   rotateF)r   r!   _visibleonselectr^   r   r{   connect_default_eventsr  _state_modifier_keysr  _use_data_coordinatesr  r   r   validButtons_selection_completed_eventpress_eventrelease_prev_eventr.  _state)r   rW   r  r{   r1  state_modifier_keysuse_data_coordinatesr   s          r    r!   _SelectorWidget.__init__.  s    .DM$M<4;;#<#<##%$(c07	03%5! 	!!(()<)BC%9"fh''!'D & %*!  !er#   c                 V   > [         TU ]  U5        U(       a  U R                  S 5        g g r   )r   rE   update_background)r   rD   r   s     r    rE   _SelectorWidget.set_activeQ  s&    6"""4( r#   c                 z   ^  [        U 4S jT R                  R                  5       R                  5        5       5      $ )a  
Convenience method to get all animated artists of the figure containing
this widget, excluding those already present in self.artists.
The returned tuple is not sorted by 'z_order': z_order sorting is
valid only when considering all artists and not only a subset of all
artists.
c              3      >#    U  HH  nUR                  5         H0  nUR                  5       (       d  M  UTR                  ;  d  M,  Uv   M2     MJ     g 7fr   )get_childrenget_animatedartists)r  ax_ar   s      r    r  8_SelectorWidget._get_animated_artists.<locals>.<genexpr>^  sL      D"A3!..0( -.dll-B Q0 "As   -AAA)tuplerW   r]   get_axesr   s   `r    _get_animated_artists%_SelectorWidget._get_animated_artistsV  s8      D$''"4"4"6"?"?"A D D 	Dr#   c                 0   U R                   (       d  g[        U R                  U R                  5       -   S S9n[	        S U 5       5      n[        5        nU(       aA  U H!  nUR                  UR                  SS95        M#     U R                  R                  5         U R                  R                  U R                  R                  5      U l        SSS5        U(       a%  U H  nU R                  R                  U5        M      gg! , (       d  f       N;= f)z"Force an update of the background.Nc                 "    U R                  5       $ r   
get_zorderr%  s    r    r_   3_SelectorWidget.update_background.<locals>.<lambda>p  s
    q||~r#   rU  c              3   @   #    U  H  oR                  5       v   M     g 7fr   )get_visible)r  artists     r    r  4_SelectorWidget.update_background.<locals>.<genexpr>q  s     FgF--//gs   F)r(  )r{   sortedr#  r)  r   r   rc  _cm_setr^   r   r  rW   r   r  r   )r   rM   r#  needs_redrawrg  r4  s         r    r  !_SelectorWidget.update_backgroundb  s     || (B(B(DD57FgFF[E%F''u(EF &  ""kk88FDO  !##F+ "  [s   A=D
Dc                    U R                  SU R                  5        U R                  SU R                  5        U R                  SU R                  5        U R                  SU R                  5        U R                  SU R
                  5        U R                  SU R                  5        U R                  SU R                  5        g)	z+Connect the major canvas events to methods.r   r   r   r  r)  key_release_eventscroll_eventN)rf   r  pressr-   r  on_key_presson_key_release	on_scrollr   s    r    r  &_SelectorWidget.connect_default_events|  s    0$++>/<14<<@<)?)?@,d.?.?@.0C0CD>4>>:r#   c                 ~   U R                   (       a  U R                  R                  5       (       d  gU R                  R                  R                  U 5      (       d  g[        US5      (       d  S Ul        U R                  b  UR                  U R                  ;  a  gU R                  c#  U R                  R                  U5      S   (       + $ UR                  U R                  R                  :X  a  gU R                  R                  U5      S   (       + =(       d#    UR                  U R                  R                  :g  $ )NTr1  r   F)rD   rW   r3  r^   r  r&   r  r1  r  r  r   rL   s     r    rN   _SelectorWidget.ignore  s    {{$''"5"5"7"7{{%%//55uh''EL )LL(9(99#ww''.q111<<4++222GG$$U+A.. 8 0 0 7 77	9r#   c                 f   U R                   R                  5       (       a(  U R                   R                  SS9R                  5       c  gU R                  (       a  U R
                  b&  U R                  R                  U R
                  5        OU R                  S5        [        U R                  U R                  5       -   S S9nU H  nU R                   R                  U5        M      U R                  R                  U R                   R                  5        gU R                  R                  5         g)z@Draw using blit() or draw_idle(), depending on ``self.useblit``.Tr[   Nc                 "    U R                  5       $ r   r-  r/  s    r    r_   (_SelectorWidget.update.<locals>.<lambda>  s
    1<<>r#   r1  )rW   r3  r]   r>  r{   r  r^   r  r  r6  r#  r)  r   r   r   rC  )r   r#  r4  s      r    r  _SelectorWidget.update  s    ##%%"""-;;=E<<***4??;&&t, T\\D,F,F,HH!9;G!##F+ "KKTWW\\*KK!!#r#   c                    UR                   c  gU R                  U5      u  p#[        R                  " U/U R                  R                  5       Q76 n[        R                  " U/U R                  R                  5       Q76 nX#4$ )z/Get the xdata and ydata for event, with limits.)NN)ro   rv   r   cliprW   r  r  r  s       r    	_get_data_SelectorWidget._get_data  si    ;;,,U35 2 2 455 2 2 45|r#   c                     UR                   c  U R                  nO[        R                  " U5      nU R                  U5      u  Ul         Ul        Xl        U$ )z
Preprocess an event:

- Replace *event* by the previous event if *event* has no ``xdata``.
- Get ``xdata`` and ``ydata`` from this widget's Axes, and clip them to the axes
  limits.
- Update the previous event.
)ro   r  copyrJ  rp   rL   s     r    _clean_event_SelectorWidget._clean_event  sI     ;;$$EIIe$E#'>>%#8 U[ r#   c                 6   U R                  U5      (       d  U R                  U5      nXl        Xl        UR                  =(       d    SnUR                  SS5      nX R                  S   :X  a  U R                  R                  S5        U R                  U5        gg)z#Button press handler and validator.r  ctrlr
  r  TF)
rN   rN  r  r  rU  replacer  r  add_press)r   rM   rU  s      r    r=  _SelectorWidget.press  s}    {{5!!%%e,E$$))/rC++fi0C//77'KKr#   c                     g)Button press event handler.Nr=   rL   s     r    rT  _SelectorWidget._press      r#   c                     U R                  U5      (       dc  U R                  (       aR  U R                  U5      nXl        U R	                  U5        SU l        SU l        U R
                  R                  S5        gg)z+Button release event handler and validator.Nr  TF)rN   r  rN  r  r   r  discardrL   s     r    r-   _SelectorWidget.release  sc    {{5!!d&6&6%%e,E!&MM% #D!%DKK'r#   c                     g)Button release event handler.Nr=   rL   s     r    r   _SelectorWidget._release  rY  r#   c                     U R                  U5      (       d4  U R                  (       a#  U R                  U5      nU R                  U5        gg)(Cursor move event handler and validator.TF)rN   r  rN  _onmoverL   s     r    r  _SelectorWidget.onmove  s;    {{5!!d&6&6%%e,ELLr#   c                     g)Cursor move event handler.Nr=   rL   s     r    rb  _SelectorWidget._onmove  rY  r#   c                 T    U R                  U5      (       d  U R                  U5        gg)z)Mouse scroll event handler and validator.N)rN   
_on_scrollrL   s     r    r@  _SelectorWidget.on_scroll  s"    {{5!!OOE" "r#   c                     g)zMouse scroll event handler.Nr=   rL   s     r    rh  _SelectorWidget._on_scroll  rY  r#   c                 $   U R                   (       a  UR                  =(       d    SnUR                  SS5      nX R                  S   :X  a  U R	                  5         gU R                  R                  5        H  u  p4XBR                  S5      ;   d  M  US:X  aI  X0R                  ;   a  U R                  R                  U5        MM  U R                  R                  U5        Mj  U R                  R                  U5        M     U R                  U5        gg)z@Key press event handler and validator for all selection widgets.r  rQ  r
  r  N+r  )rD   rU  rR  r  r  r  splitr  r[  rS  _on_key_pressr   rM   rU  r  modifiers        r    r>  _SelectorWidget.on_key_press	  s    ;;))/rC++fi0C//88

%)%>%>%D%D%F!yy~- ( KK/ KK//6 KKOOE2. &G u%# r#   c                     g)z@Key press event handler - for widget-specific key press actions.Nr=   rL   s     r    ro  _SelectorWidget._on_key_press	  rY  r#   c                 ,   U R                   (       a  UR                  =(       d    SnU R                  R                  5        H>  u  p4XBR	                  S5      ;   d  M  US:w  d  M#  U R
                  R                  U5        M@     U R                  U5        gg)z(Key release event handler and validator.r  rm  r  N)rD   rU  r  r  rn  r  r[  _on_key_releaserp  s        r    r?  _SelectorWidget.on_key_release	  sq    ;;))/rC%)%>%>%D%D%F! yy~-%82CKK''.	 &G
   ' r#   c                     g)Key release event handler.Nr=   rL   s     r    rv  _SelectorWidget._on_key_release$	  rY  r#   c                 X    Xl         U R                   H  nUR                  U5        M     g)z+Set the visibility of the selector artists.N)r  r#  r  )r   r(  r4  s      r    r  _SelectorWidget.set_visible'	  s#    llFw' #r#   c                     U R                   $ )z+Get the visibility of the selector artists.)r  r   s    r    r3  _SelectorWidget.get_visible-	  s    }}r#   c                 D    U R                  5         U R                  5         g)zAClear the selection and set the selector ready to make a new one.N)_clear_without_updater  r   s    r    r  _SelectorWidget.clear1	  s    ""$r#   c                 4    SU l         U R                  S5        g NF)r  r  r   s    r    r  %_SelectorWidget._clear_without_update6	  s    $)!r#   c                 <    [        U SS5      nU R                  4U-   $ )z%Tuple of the artists of the selector._handles_artistsr=   )r_  _selection_artist)r   handles_artistss     r    r#  _SelectorWidget.artists:	  s'     "$(:B?&&(?::r#   c                     U R                   n[        R                  " X5      nUR                  " S0 UD6  U R                  (       a  U R                  5         gg)z
Set the properties of the selector artist.

See the *props* argument in the selector docstring to know which properties are
supported.
Nr=   )r  r   r  r.  r{   r  )r   r  r4  s      r    	set_props_SelectorWidget.set_props@	  sC     ''&&u5

U<<KKM r#   c                 H   [        U S5      (       d  [        S5      eU R                  S   n[        R                  " X5      nU R                   H  nUR
                  " S0 UD6  M     U R                  (       a  U R                  5         U R                  R                  U5        g)z
Set the properties of the handles selector artist. See the
`handle_props` argument in the selector docstring to know which
properties are supported.
r  z#This selector doesn't have handles.r   Nr=   )	r  NotImplementedErrorr  r   r  r.  r{   r  _handle_props)r   handle_propsr4  r  s       r    set_handle_props _SelectorWidget.set_handle_propsM	  s     t/00%&KLL&&q)--lC++FJJ&& ,<<KKM!!,/r#   c                     U R                   R                  5        VVs/ s H  u  p#US:w  d  M  US:w  d  M  UPM     nnn[        R                  " XAS9  g s  snnf )Nr  not-applicabler  )r  r  r   r   )r   r  rU  valuesupported_states        r    _validate_state_SelectorWidget._validate_state^	  s]    "&";";"A"A"C"CJCg~ "'+;"; "C 	  	?8	s   AAAc                 \    U R                  U5        U R                  R                  U5        g)a@  
Add a state to define the widget's behavior. See the
`state_modifier_keys` parameters for details.

Parameters
----------
state : str
    Must be a supported state of the selector. See the
    `state_modifier_keys` parameters for details.

Raises
------
ValueError
    When the state is not supported by the selector.

N)r  r  rS  r   r  s     r    	add_state_SelectorWidget.add_statee	  s"    " 	U#r#   c                 \    U R                  U5        U R                  R                  U5        g)aC  
Remove a state to define the widget's behavior. See the
`state_modifier_keys` parameters for details.

Parameters
----------
state : str
    Must be a supported state of the selector. See the
    `state_modifier_keys` parameters for details.

Raises
------
ValueError
    When the state is not supported by the selector.

N)r  r  r  r  s     r    remove_state_SelectorWidget.remove_statey	  s$    " 	U#5!r#   )r  r  r  r  r  r  r  r  r  r  r{   r  )NFNNF)&r7   r8   r9   r:   r!   rE   r)  r  r  rN   r  rJ  rN  r=  rT  r-   r   r  rb  r@  rh  r>  ro  r?  rv  r  r3  r  r  rR   r#  r  r  r  r  r  r<   r   r   s   @r    r  r  ,  s    @D@E!F)

D,4;90$*"*
,)#
*&*O	()(
  ; ;
0"9(" "r#   r  c                   *  ^  \ rS rSrSrSSSSSSSSSSSSS.U 4S jjrSSS	.S
 jrS r\S 5       r	S r
U 4S jrS r\S 5       r\R                  S 5       rS rS rS rS rS rS r\S 5       r\S 5       r\R                  S 5       rS rSrU =r$ )SpanSelectori	  a  
Visually select a min/max range on a single axis and call a function with
those values.

To guarantee that the selector remains responsive, keep a reference to it.

In order to turn off the SpanSelector, set ``span_selector.active`` to
False.  To turn it back on, set it to True.

Press and release events triggered at the same coordinates outside the
selection will clear the selector, except when
``ignore_event_outside=True``.

Parameters
----------
ax : `~matplotlib.axes.Axes`

onselect : callable with signature ``func(min: float, max: float)``
    A callback function that is called after a release event and the
    selection is created, changed or removed.

direction : {"horizontal", "vertical"}
    The direction along which to draw the span selector.

minspan : float, default: 0
    If selection is less than or equal to *minspan*, the selection is
    removed (when already existing) or cancelled.

useblit : bool, default: False
    If True, use the backend-dependent blitting features for faster
    canvas updates. See the tutorial :ref:`blitting` for details.

props : dict, default: {'facecolor': 'red', 'alpha': 0.5}
    Dictionary of `.Patch` properties.

onmove_callback : callable with signature ``func(min: float, max: float)``, optional
    Called on mouse move while the span is being selected.

interactive : bool, default: False
    Whether to draw a set of handles that allow interaction with the
    widget after it is drawn.

button : `.MouseButton` or list of `.MouseButton`, default: all buttons
    The mouse buttons which activate the span selector.

handle_props : dict, default: None
    Properties of the handle lines at the edges of the span. Only used
    when *interactive* is True. See `.Line2D` for valid properties.

grab_range : float, default: 10
    Distance in pixels within which the interactive tool handles can be activated.

state_modifier_keys : dict, optional
    Keyboard modifiers which affect the widget's behavior.  Values
    amend the defaults, which are:

    - "clear": Clear the current shape, default: "escape".

drag_from_anywhere : bool, default: False
    If `True`, the widget can be moved by clicking anywhere within its bounds.

ignore_event_outside : bool, default: False
    If `True`, the event triggered outside the span selector will be ignored.

snap_values : 1D array-like, optional
    Snap the selector edges to the given values.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> import matplotlib.widgets as mwidgets
>>> fig, ax = plt.subplots()
>>> ax.plot([1, 2, 3], [10, 50, 100])
>>> def onselect(vmin, vmax):
...     print(vmin, vmax)
>>> span = mwidgets.SpanSelector(ax, onselect, 'horizontal',
...                              props=dict(facecolor='blue', alpha=0.5))
>>> fig.show()

See also: :doc:`/gallery/widgets/span_selector`
r   FNr   )minspanr{   r  onmove_callbackinteractiver1  r  
grab_ranger  drag_from_anywhereignore_event_outsidesnap_valuesc                  > Uc  [        SSSSS9n[        TU ]	  XXYUS9  Uc
  [        SSS9nU R                  US'   X0l        S U l        Xl        Xpl        X@l        Xl	        Xl
        S U l        Xl        Xl        U R                  XS	S
9  SUR                  SS5      0[         R"                  " U
[$        5      EU l        U R                  (       a$  SS/U l        U R+                  U R&                  5        S U l        g )Nr  r  )r  r  r~   r  )r{   r1  r  redr}   )r  alphar  T_props_initr   r  r   ro  rt  )r  r   r!   r{   	direction_extents_on_pressr  r  r  r  _interactive_edge_handlesr  r  new_axesr  r   r  r   r  _edge_order_setup_edge_handlesr_  )r   rW   r  r  r  r{   r  r  r  r1  r  r  r  r  r  r  r   s                   r    r!   SpanSelector.__init__	  s    &"&X.>.>.>#@ 	w-@ 	 	B =54E LLj"!%&.$'!"4$8!bd3 UYY{C0<$$\6:<  %u~D$$T%7%78"r#   r  c                .   SnU(       d&  U R                   UR                  SS9R                   La  U R                   b  U R                  5         SnXl        U(       a  U R	                  5         SU l        U R                  S:X  a  UR                  5       nSu  pgOUR                  5       nSu  pg[        SXgUSS	9nUb  UR                  U5        O(U R                  b  UR                  U R                  5        U R                  R                  U5        Xl        g)
z*Set SpanSelector to operate on a new Axes.FTr[   Nr   r"  )r   r   r   r   )rs   r(  )r^   r]   rk   rW   r  r  r  rW  rV  r   r  r  update_fromr  )	r   rW   r  r  	reconnecttranswr  rect_artists	            r    r  SpanSelector.new_axes
  s    	DKKr}}$}'?'F'FF{{&&&(I'') %*!>>\)**,EDAq**,EDAuMv&##/##D$:$:;+&!,r#   c                     U R                   S:X  a  U R                  R                  5       nOU R                  R                  5       n[	        U R                  UU R                   UU R
                  S9U l        g )Nr   )r  
line_propsr{   )r  rW   r  r  ToolLineHandlesr{   r  )r   r  	positionss      r    r   SpanSelector._setup_edge_handles+
  sY    >>\)**,I**,I,TWWi7;~~8=59\\Cr#   c                 J    U R                   b  U R                   R                  $ gr  )r  r#  r   s    r    r  SpanSelector._handles_artists6
  s#    )%%---r#   c                 4   U(       aE  U R                   S:X  a  [        R                  R                  O[        R                  R                  nO[        R                  R
                  nU R                  R                  SS9R                  R                  U5        g)z<Update the canvas cursor based on direction of the selector.r   Tr[   N)
r  r
   CursorsRESIZE_HORIZONTALRESIZE_VERTICALPOINTERrW   r]   r^   
set_cursor)r   enabledr3  s      r    _set_cursorSpanSelector._set_cursor=
  so    <7 $++==#++;;  #**22F%,,77?r#   c                    > [         TU ]  5         [        U SS5      (       a  U R                  SU R                  5        g g )Nr  Fr   )r   r  r_  rf   _hover)r   r   s    r    r  #SpanSelector.connect_default_eventsH
  s7    &(4//4dkkB 0r#   c                    U R                  S5        U R                  (       a1  U R                  R                  5       (       a  U R	                  U5        OSU l        U R
                  b  U R                  (       d  U R                  5         U R                  U5      u  p#U R                  S:X  a  UOUnU R
                  c2  U R                  (       d!  SU l
        U R                  XD45        SU l
        gU R                  S5        g)rW  TNr   F)r  r  r  r3  _set_active_handler_  r  rv   r  r  r  _set_extentsr  )r   rM   ro   rp   r(  s        r    rT  SpanSelector._pressN
  s    !7!7!C!C!E!E##E*"&D&d.?.?KKM,,U3^^|3E&t/H/H "DMqf% !DM  T"r#   c                     U R                   $ )z;Direction of the span selector: 'vertical' or 'horizontal'.
_directionr   s    r    r  SpanSelector.directionk
       r#   c                    [         R                  " SS/US9  [        U S5      (       a  XR                  :w  a  U R                  R                  5         U R                  (       a  U R                  R                  5         Xl        U R                  U R                  5        U R                  (       a  U R                  U R                  5        ggXl        g)z'Set the direction of the span selector.r   r   r  r  N)r   r   r  r  r  r  r  r  r  rW   r  r  )r   r  s     r    r  r  p
  s     	L*5K4&&9+G""))+  ""))+'OMM$''"  ((););< ! (Or#   c                    U R                  S5        U R                  (       d  U R                  R                  S5        U R                  c#  U R
                  (       a  U R                  (       a  gU R                  u  p#X2-
  nX@R                  ::  a;  U R                  S5        U R
                  (       a  U R                  X#5        SU l        OU R                  X#5        SU l        U R                  5         SU l        g)r^  FNT)r  r  r  r  r_  r  r  extentsr  r  r  )r   rM   ri  rj  spans        r    r   SpanSelector._release
  s      ""..u5'D,E,E))\\
{<<U#((d)(-D%MM$%(,D%"r#   c                    U R                  U5      (       a  gU R                  c  U R                  (       d  gU R                  R	                  UR
                  UR                  5      u  p#U R                  X0R                  :*  5        g)z/Update the canvas cursor if it's over a handle.N)	rN   r_  r  r  closestrt   ru   r  r  )r   rM   r8  e_dists       r    r  SpanSelector._hover
  sd    ;;u*$2K2K
 &&..uww@	??23r#   c                 ^   U R                  U5      u  p#U R                  S:X  a  UnU R                  R                  nOUnU R                  R                  nU R
                  S:X  a(  U R                  b  U R                  u  pgXE-
  nXh-  nXx-  nOqU R
                  (       a4  U R
                  S:w  a$  U R                  u  pgU R
                  S:X  a  UnO/UnO,U R                  (       a  U R                  (       a  gXTpvXg:  a  XvpvU R                  Xg45        U R                  b  U R                  Xg5        g)zMotion notify event handler.r   CNro  F)rv   r  r  ro   rp   r_  r  r  r  r  r  )	r   rM   ro   rp   r(  vpressri  rj  dvs	            r    rb  SpanSelector._onmove
  s    ,,U3>>\)A%%++FA%%++F
 #%$*@*@*L//JDBJDJD   T%8%8C%?//JD""e+
 ((T-F-F${!d4,'+  ,r#   c                    X:  a  X!p!U R                   S:X  a9  U R                  R                  U5        U R                  R                  X!-
  5        g U R                  R	                  U5        U R                  R                  X!-
  5        g )Nr   )r  r  set_xr?  set_yr<  r   ri  rj  s      r    _draw_shapeSpanSelector._draw_shape
  sl    ;$>>\)""((."",,T[9""((.""--dk:r#   c                    U R                   R                  UR                  UR                  5      u  p#SU R                  ;   a  SU l        OrX0R                  :  aO  SU l        U R                  (       a/  U R                  U5      (       a  SU l        U R                  U l
        OSU l        gU R                  U   U l        U R                  U l
        g);Set active handle based on the location of the mouse event.r  r  N)r  r  rt   ru   r  r_  r  r  	_containsr  r  r  )r   rM   e_idxr  s       r    r  SpanSelector._set_active_handle
  s     **22577EGGD T[[ "%Doo%"&D&&4>>%+@+@&)#)-&&*# #'"2"25"9D "&r#   c                 <    U R                   R                  USS9S   $ z)Return True if event is within the patch.r   )radiusr  r   rL   s     r    r  SpanSelector._contains
  #    %%..uQ.?BBr#   c                    ^^ [         R                  " [         R                  " [         R                  " T5      5      5      S-  m[	        UU4S jU  5       5      $ )z2Snap values to a given array values (snap_values).g-q=c              3      >#    U  HI  nT[         R                  " TU-
  [         R                  " U5      T-  -   5      R                  5          v   MK     g 7fr   )r   r   signr   )r  r(  epsr  s     r    r  %SpanSelector._snap.<locals>.<genexpr>  sE       {Qc1AABIIKLs   AA)r   ro  r   diffr'  )valuesr  r  s    `@r    _snapSpanSelector._snap  sD     ffRVVBGGK012U:   	r#   c                    U R                   S:X  a9  U R                  R                  5       nXR                  R                  5       -   nX4$ U R                  R	                  5       nXR                  R                  5       -   nX4$ )z
(float, float)
    The values, in data coordinates, for the start and end points of the current
    selection. If there is no selection then the start and end values will be
    the same.
r   )r  r  r@  	get_widthr=  
get_heightr  s      r    r  SpanSelector.extents  sz     >>\)))//1D00::<<D z ))//1D00;;==Dzr#   c                 4    U R                  U5        SU l        g NT)r  r  r   r  s     r    r  r    s    '"$(!r#   c                 F   U R                   b$  [        U R                  XR                   5      5      nU R                  " U6   U R                  (       a%  U R
                  R                  U R                  5        U R                  U R                  5        U R                  5         g r   )r  r'  r  r  r  r  set_datar  r  r  r  r
  s     r    r  SpanSelector._set_extents   sq    'DJJw0@0@ABG'"''5'r#   )r_  r  r  r  r  r  r  r  r  r  rW   r  r  r  r  r  r  r  )r7   r8   r9   r:   r;   r!   r  r  rR   r  r  r  rT  r  r  r   r  rb  r  r  r  staticmethodr  r  r  r<   r   r   s   @r    r  r  	  s   Pd <=eTu4B%)e&+	+# +#Z &* -:	C  	@C:   ( (>4*X;.4C     ^^) )	 	r#   r  c                   v    \ rS rSrSrSSS.S jr\S 5       r\S 5       r\S	 5       r	S
 r
S rS rS rS rSrg)r  i,  a   
Control handles for canvas tools.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    Matplotlib Axes where tool handles are displayed.
positions : 1D array
    Positions of handles in data coordinates.
direction : {"horizontal", "vertical"}
    Direction of handles, either 'vertical' or 'horizontal'
line_props : dict, optional
    Additional line properties. See `.Line2D`.
useblit : bool, default: True
    Whether to use blitting for faster drawing (if supported by the
    backend). See the tutorial :ref:`blitting`
    for details.
NT)r  r{   c                    Xl         [        R                  " SS/US9  X0l        0 Ub  UO0 ESUS.EnU R                  S:X  a  UR
                  OUR                  nU Vs/ s H  ov" U40 UD6PM     snU l        g s  snf )Nr   r   r  F)r(  r  )rW   r   r   r  r  r  r  _artists)r   rW   r  r  r  r{   line_funps           r    r!   ToolLineHandles.__init__@  s    L*5K#
'3z


 "&<!?2::RZZ<EFIq!2z2IFFs   A9c                 ,    [        U R                  5      $ r   )r'  r  r   s    r    r#  ToolLineHandles.artistsQ  s    T]]##r#   c                     U R                   S:X  a  SOSnU R                   Vs/ s H  n[        X!5      " 5       S   PM     sn$ s  snf )z,Positions of the handle in data coordinates.r   r  r  r   )r  r#  r_  )r   methodr  s      r    r  ToolLineHandles.positionsU  s?     !%, >K7;||D|t%'*|DDDs   Ac                     U R                   $ )z4Direction of the handle: 'vertical' or 'horizontal'.r  r   s    r    r  ToolLineHandles.direction[  r  r#   c                     U R                   S:X  a  SOSn[        U R                  U5       H  u  p4[        X25      " XD/5        M     g)z
Set x- or y-positions of handles, depending on if the lines are
vertical or horizontal.

Parameters
----------
positions : tuple of length 2
    Set the positions of the handle in data coordinates
r   rA  r>  N)r  r  r#  r_  )r   r  r  r  r  s        r    r  ToolLineHandles.set_data`  s<     !%, >K4<<3GDD!1&) 4r#   c                 L    U R                    H  nUR                  U5        M     g)z/Set the visibility state of the handles artist.N)r#  r  r   r  r4  s      r    r  ToolLineHandles.set_visiblen  s    llFu% #r#   c                 L    U R                    H  nUR                  U5        M     g)z-Set the animated state of the handles artist.N)r#  set_animatedr  s      r    r"  ToolLineHandles.set_animateds  s    llF& #r#   c                 J    U R                    H  nUR                  5         M     g)z*Remove the handles artist from the figure.N)r  r  )r   r4  s     r    r  ToolLineHandles.removex  s    mmFMMO $r#   c           	         U R                   S:X  af  [        R                  " U R                   Vs/ s H,  o0R                  R
                  R                  US45      S   PM.     sn5      n[        XA-
  5      nOe[        R                  " U R                   Vs/ s H,  o0R                  R
                  R                  SU45      S   PM.     sn5      n[        XB-
  5      n[        R                  " U5      nXeU   4$ s  snf s  snf )a  
Return index and pixel distance to closest handle.

Parameters
----------
x, y : float
    x, y position from which the distance will be calculated to
    determinate the closest handle

Returns
-------
index, distance : index of the handle and its distance from
    position x, y
r   r   r   )	r  r   rU  r  rW   rq   rs   r   r   )r   rt   ru   r  p_ptsdistr  s          r    r  ToolLineHandles.closest}  s     >>\)HH@D@N1!!++QF3A6 E uy>DHH@D@N1!!++QF3A6 E uy>D		$5k!!
s   3C83C=)r  r  rW   )r7   r8   r9   r:   r;   r!   rR   r#  r  r  r  r  r"  r  r  r<   r=   r#   r    r  r  ,  sn    & @DG" $ $ E E
  *&
'

"r#   r  c                   v    \ rS rSrSrSSSS.S jr\S 5       r\S	 5       r\S
 5       r	SS jr
S rS rS rSrg)ToolHandlesi  a  
Control handles for canvas tools.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    Matplotlib Axes where tool handles are displayed.
x, y : 1D arrays
    Coordinates of control handles.
marker : str, default: 'o'
    Shape of marker used to display handle. See `~.pyplot.plot`.
marker_props : dict, optional
    Additional marker properties. See `.Line2D`.
useblit : bool, default: True
    Whether to use blitting for faster drawing (if supported by the
    backend). See the tutorial :ref:`blitting`
    for details.
r)   NTr  r)  r{   c                    Xl         USSSSSSS.[        R                  " U[        R                  5      En[        X#4SU0UD6U l        U R                   R                  U R
                  5        g )	N   r  r  r}   F
_nolegend_)r  
markersizemarkerfacecolor	linestyler  r(  r   r  )rW   r   r  r   
_alias_map_markersadd_line)r   rW   rt   ru   r  r)  r{   r  s           r    r!   ToolHandles.__init__  sl    !s$su&L )),8I8IJL q?g??'r#   c                 6    U R                   R                  5       $ r   )r4  r  r   s    r    rt   ToolHandles.x      }}&&((r#   c                 6    U R                   R                  5       $ r   )r4  r  r   s    r    ru   ToolHandles.y  r9  r#   c                     U R                   4$ r   )r4  r   s    r    r#  ToolHandles.artists  s      r#   c                 r    Ub  Un[         R                  " X2/5      nU R                  R                  U5        g)z!Set x and y positions of handles.N)r   rU  r4  r  )r   ptsru   rt   s       r    r  ToolHandles.set_data  s.    =A((A6"Cs#r#   c                 :    U R                   R                  U5        g r   )r4  r  r-  s     r    r  ToolHandles.set_visible  s    !!#&r#   c                 :    U R                   R                  U5        g r   )r4  r"  r-  s     r    r"  ToolHandles.set_animated  s    ""3'r#   c                 "   [         R                  " U R                  U R                  /5      nU R                  R
                  R                  U5      nX1U/-
  n[         R                  " UR                  6 n[         R                  " U5      nXeU   4$ )z1Return index and pixel distance to closest index.)
r   column_stackrt   ru   rW   rq   rs   hypotTr   )r   rt   ru   r?  r   r(  	min_indexs          r    r  ToolHandles.closest  sn    ootvvtvv./gg))#.V|xx IIdO	y/))r#   )r4  rW   r   )r7   r8   r9   r:   r;   r!   rR   rt   ru   r#  r  r  r"  r  r<   r=   r#   r    r+  r+    se    & ,/T4 ( ) ) ) ) ! !$'(*r#   r+  u  
    Parameters
    ----------
    ax : `~matplotlib.axes.Axes`
        The parent Axes for the widget.

    onselect : function, optional
        A callback function that is called after a release event and the
        selection is created, changed or removed.
        It must have the signature::

            def onselect(eclick: MouseEvent, erelease: MouseEvent)

        where *eclick* and *erelease* are the mouse click and release
        `.MouseEvent`\s that start and complete the selection.

    minspanx : float, default: 0
        Selections with an x-span less than or equal to *minspanx* are removed
        (when already existing) or cancelled.

    minspany : float, default: 0
        Selections with an y-span less than or equal to *minspanx* are removed
        (when already existing) or cancelled.

    useblit : bool, default: False
        Whether to use blitting for faster drawing (if supported by the
        backend). See the tutorial :ref:`blitting`
        for details.

    props : dict, optional
        Properties with which the __ARTIST_NAME__ is drawn. See
        `.Patch` for valid properties.
        Default:

        ``dict(facecolor='red', edgecolor='black', alpha=0.2, fill=True)``

    spancoords : {"data", "pixels"}, default: "data"
        Whether to interpret *minspanx* and *minspany* in data or in pixel
        coordinates.

    button : `.MouseButton`, list of `.MouseButton`, default: all buttons
        Button(s) that trigger rectangle selection.

    grab_range : float, default: 10
        Distance in pixels within which the interactive tool handles can be
        activated.

    handle_props : dict, optional
        Properties with which the interactive handles (marker artists) are
        drawn. See the marker arguments in `.Line2D` for valid
        properties.  Default values are defined in ``mpl.rcParams`` except for
        the default value of ``markeredgecolor`` which will be the same as the
        ``edgecolor`` property in *props*.

    interactive : bool, default: False
        Whether to draw a set of handles that allow interaction with the
        widget after it is drawn.

    state_modifier_keys : dict, optional
        Keyboard modifiers which affect the widget's behavior.  Values
        amend the defaults, which are:

        - "move": Move the existing shape, default: no modifier.
        - "clear": Clear the current shape, default: "escape".
        - "square": Make the shape square, default: "shift".
        - "center": change the shape around its center, default: "ctrl".
        - "rotate": Rotate the shape around its center between -45° and 45°,
          default: "r".

        "square" and "center" can be combined. The square shape can be defined
        in data or display coordinates as determined by the
        ``use_data_coordinates`` argument specified when creating the selector.

    drag_from_anywhere : bool, default: False
        If `True`, the widget can be moved by clicking anywhere within
        its bounds.

    ignore_event_outside : bool, default: False
        If `True`, the event triggered outside the span selector will be
        ignored.

    use_data_coordinates : bool, default: False
        If `True`, the "square" shape of the selector is defined in
        data coordinates instead of display coordinates.
    __ARTIST_NAME__	rectanglec                   N  ^  \ rS rSrSrSSSSSSSSSSSSSSS.U 4S	 jjjr\S
 5       rS rS r	S r
S r\S 5       rS rS r\S 5       r\S 5       r\S 5       r\S 5       r\R&                  S 5       r\S 5       r\R&                  S 5       rS rS rS r\S 5       rSrU =r$ )RectangleSelectori3  a2  
Select a rectangular region of an Axes.

For the cursor to remain responsive you must keep a reference to it.

Press and release events triggered at the same coordinates outside the
selection will clear the selector, except when
``ignore_event_outside=True``.

%s

Examples
--------
>>> import matplotlib.pyplot as plt
>>> import matplotlib.widgets as mwidgets
>>> fig, ax = plt.subplots()
>>> ax.plot([1, 2, 3], [10, 50, 100])
>>> def onselect(eclick, erelease):
...     print(eclick.xdata, eclick.ydata)
...     print(erelease.xdata, erelease.ydata)
>>> props = dict(facecolor='blue', alpha=0.5)
>>> rect = mwidgets.RectangleSelector(ax, onselect, interactive=True,
...                                   props=props)
>>> fig.show()
>>> rect.add_state('square')

See also: :doc:`/gallery/widgets/rectangle_selector`
Nr   Fdatar   )minspanxminspanyr{   r  
spancoordsr1  r  r  r  r  r  r  r  c          	      >  > [         TU ]  XXXUUS9  Xl        Xl        Xl        SU l        SU l        SU l        Uc  [        SSSSS9n0 UES	U R                  0EnUR                  S
U R                  5      U l        U R                  " S0 UD6nU R                  R                  U5        UU l        U R!                  5         X0l        X@l        [&        R(                  " SS/US9  Xpl        Xl        U R                  (       Ga  SU=(       d    0 R/                  SS5      0[0        R2                  " U
[4        5      EU l        / SQU l        U R:                  u  nn[=        U R                  UUU R6                  U R                  S9U l        / SQU l         U RB                  u  nn[=        U R                  UUSU R6                  U R                  S9U l"        U RF                  u  nn[=        U R                  U/U/SU R6                  U R                  S9U l$        S U l%        S U l&        g )N)r{   r1  r  r  g        g      ?Tr  r  r  )r  r  r  fillr  r(  rO  pixelsrR  markeredgecolorr  )SWSENENW)r)  r{   )WSENr9  r,  r=   )'r   r!   r  r  r  	_rotation_aspect_ratio_correction_allow_creationr  r{   r  r  _init_shaperW   r  r  _set_aspect_ratio_correctionrP  rQ  r   r   rR  r  r  r   r  r   r  _corner_ordercornersr+  _corner_handlesr  edge_centersr  r~   _center_handler_  r  )r   rW   r  rP  rQ  r{   r  rR  r1  r  r  r  r  r  r  r  to_drawxcycxeyer   s                        r    r!   RectangleSelector.__init__S  s    	w-@.B 	 	D ("4$8!(+%
  $=5G"/E353*dll3		)T]];""+U+'"!())+  FH-*E$$!EKR#4#4['#J"@((v>"@D ":D\\FB#.twwB<@<N<N7;||$ED   4D&&FB!,TWWb"S:>:L:L59\\"CD [[FB"-dggtbT#;?;M;M6:ll#DD #'D!%r#   c                     / U R                   R                  QU R                  R                  QU R                  R                  Q7$ r   )ri  r#  rg  r  r   s    r    r  "RectangleSelector._handles_artists  sF    -$$,, -t/C/C/K/K -##++- 	-r#   c                     [        SSSS.UD6$ )Nr  r   r   Fr~   )r(  rotation_point)r   r  s     r    rc  RectangleSelector._init_shape  s!     ;u(0;49; 	;r#   c                 N   U R                   (       a1  U R                  R                  5       (       a  U R                  U5        OSU l        U R                  b  U R                   (       d!  U R
                  (       a  U R                  5         U R                  cM  U R                  (       d<  U R
                  (       a+  U R                  U5      u  p#SU l	        X"X34U l
        SU l	        OU R                  S5        U R                  U l        U R                  U l        U R                  5         g)rW  NFT)r  r  r3  r  r_  rb  r  r  rv   r  r  r  r  r`  _rotation_on_pressrd  )r   rM   rt   ru   s       r    rT  RectangleSelector._press  s     !7!7!C!C!E!E##E*"&D  (0A0A$$KKM'0I0I$$((/DA!DM:DL DMT"!%"&..))+r#   c                    U R                   (       d  U R                  R                  S5        U R                  c#  U R                  (       a  U R
                  (       a  gU R                  u  p#pEX R                  l        X@R                  l	        U R                  R                  R                  X$/5      nUu  U R                  l        U R                  l        X0R                  l        XPR                  l	        U R                  R                  R                  X5/5      nUu  U R                  l        U R                  l        U R                   S:X  am  [#        U R                  R                  U R                  R                  -
  5      n[#        U R                  R                  U R                  R                  -
  5      n	OU R                   S:X  am  [#        U R                  R                  U R                  R                  -
  5      n[#        U R                  R                  U R                  R                  -
  5      n	O![$        R&                  " SS/U R                   S9  WU R(                  ::  d  W	U R*                  ::  aH  U R                  (       a&  U R-                  U R                  U R                  5        U R/                  5         O-U R-                  U R                  U R                  5        SU l        U R1                  5         SU l        SU l        g)r^  FNrO  rU  rV  T)r  r  r  r_  r  r  r  r  ro   rp   rW   rq   rs   rt   ru   r  rR  r   r   r   rP  rQ  r  r  r  r  )
r   rM   rC  rD  r@  rA  xy0xy1spanxspanys
             r    r   RectangleSelector._release  sF     ""..u5'D,E,E)) !#!#gg))2(314.D,,.#% #% gg))2(3582d002 ??f$((..1C1C1I1IIJE((..1C1C1I1IIJE__(((**T-?-?-A-AABE((**T-?-?-A-AABE1*.//; DMM!Udmm%;((d..0B0BC&&(MM$**D,>,>?(,D%"!%r#   c                    U R                   nU R                  nSU;   =(       a    U R                  U R                  ;   nU R                  S:H  nU R                  =(       a    U(       + nU R	                  U5      u  pxU(       af  U R                  5       R                  5       n	U	R                  Xx/5      u  pxU	R                  UR                  UR                  45      u  Ul        Ul	        XrR                  -
  n
XR                  -
  nSnU R                  (       a  XpO2UR                  UR                  -
  nUR                  UR                  -
  nU R                  u  nnnnU(       a  UR                  UR                  4nU R                  nXx4n[        R                   " US   US   -
  US   US   -
  5      [        R                   " US   US   -
  US   US   -
  5      -
  n[        R"                  " U R$                  U-   5      U l        GOU(       GaO  UU-
  UU-
  /nUUS   S-  -   UUS   S-  -   4nSU;   Ga  SU;   am  U R                  U R                  ;   a  [)        X[*        S	9nU R                  S
;   d  X:X  a  UUS   -
  nUU R,                  -  nOUUS   -
  nUU R,                  -  nOpUS   S-  nUS   S-  nU R                  SS/U R                  -   ;   a  [+        UUS   -
  5      nU R                  SS/U R                  -   ;   a  [+        UUS   -
  5      nUS   U-
  US   U-   US   U-
  US   U-   4u  nnnnGOSU R                  ;   a  UnSU R                  ;   a  UnU R                  SS/U R                  -   ;   a  UnU R                  SS/U R                  -   ;   a  UnSU;   a  U R                  U R                  ;   a  [)        X[*        S	9nU R                  S
;   d  X:X  a<  [        R.                  " UU-
  5      nUU[+        UU-
  5      -  U R,                  -  -   nGO[        R.                  " X-
  5      nUU[+        UU-
  5      -  U R,                  -  -   nGOxU(       aB  U R                  u  nnnnXrR                  -
  n
XR                  -
  nX-  nUU
-  nUU-  nUU-  nGO/SU l        U R2                  (       a  U R4                  (       d  U R6                  (       d  gUR                  UR                  /nUUS   -
  S-  n
UUS   -
  S-  nSU;   ar  [)        X[*        S	9nX:X  a0  [        R.                  " U5      [+        U
5      -  U R,                  -  nO/[        R.                  " U
5      [+        U5      -  U R,                  -  n
SU;   a  U
S-  n
US-  nOUS==   U
-  ss'   US==   U-  ss'   US   U
-
  US   U
-   US   U-
  US   U-   4u  nnnnUUUU4U l        g)z
Motion notify event handler.

This can do one of four things:
- Translate
- Rotate
- Re-size
- Continue the creation of a new shape
r  r  Nr   r   rP  r~   r  r1  )r^  r\  r^  r\  r_  r]  )r  r  r_  re  rv   _get_rotation_transformrr   rs   ro   rp   r  rt   ru   r  r~   r   arctan2rad2degrw  rotationrt  r   ra  r  r`  r  r  rb  r  )r   rM   
eventpressr  r  r  resizero   rp   inv_trdxdyrefmaxrefxrefyrC  rD  r@  rA  r%  brj   anglesize_on_pressr~   hwhhr  s                               r    rb  RectangleSelector._onmove  s    %%
 U"Pt':':d>P>P'P""c)$$1T,,U3113<<>F!++UN;LE171A1A!!:#3#3426.Jj. %%%%%% %%$ 77Z\\)D77Z\\)D//BB!!:#3#34AAAZZ!QqT	1Q4!95ZZ!QqT	1Q4!956EJJt'>'>'FGDM"Wb2g.M=+a//mA6F6J1JKF 5 u$**d.@.@@!$TS!9**j8FN"VAY.$"?"??"VAY.$"?"??&q)A-B&q)A-B**sCj4;M;M.MM !23**sCj4;M;M.MM !23"()b.&)b."()b.&)b."BBB $---B$---B&&3*t7I7I*IIB&&3*t7I7I*IIBu$**d.@.@@!$TS!9**j8FN!wwurz2$R"W"58U8U"UU!wwuz2$R"W"58U8U"UU!33NBB)))B)))BHB"HB"HB"HB DN **t/H/H,, &&
(8(89F&)#q(B&)#q(B 5 TS1>s2w.1N1NNBs2w.1N1NNB 5 aa q	R	q	R	$Qi"nfQi"n$Qi"nfQi"n>NBB 2r2~r#   c                 J    U R                   R                  5       R                  $ r   )r  get_bboxboundsr   s    r    
_rect_bboxRectangleSelector._rect_bboxy  s    %%..0777r#   c                     U R                   R                  5       nXR                  l        U R                  (       a  SU l        g Xl        g )Nr   )rW   _get_aspect_ratior  ra  r  r   aspect_ratios     r    rd  .RectangleSelector._set_aspect_ratio_correction}  s7    ww002:F7%%,-D),8)r#   c                 H   U R                   R                  5       n[        5       R                  U R                  S   * U R                  S   * 5      R                  SU5      R                  U R                  5      R                  SSU-  5      R                  " U R                  6 $ Nr   r   )rW   r  r   	translater~   scaler  r`  r  s     r    r  )RectangleSelector._get_rotation_transform  s    ww002z##T[[^Odkk!n_Eq,''q!l*+	 !KK	) 	)r#   c                     U R                   u  pp4XU-   X-   U4nX"X$-   X$-   4nU R                  5       nUR                  [        R                  " XV/5      R
                  5      R
                  nUS   US   4$ )zM
Corners of rectangle in data coordinates from lower left,
moving clockwise.
r   r   r  r  rs   r   rU  rH  )	r   rC  r@  rE  rB  rk  rl  rs   r  s	            r    rf  RectangleSelector.corners  s|     !%eRZ+R["+-002	$$RXXrh%7%9%9:<<ay&)##r#   c                    U R                   u  pp4US-  nUS-  nXU-   X-   X-   4nX&-   X"U-   X$-   4nU R                  5       n	U	R                  [        R                  " Xx/5      R
                  5      R
                  n
U
S   U
S   4$ )zS
Midpoint of rectangle edges in data coordinates from left,
moving anti-clockwise.
       @r   r   r  )r   rC  r@  rE  rB  r  r  rm  rn  rs   r  s              r    rh  RectangleSelector.edge_centers  s     !%BJRKaRV+VRa,002	$$RXXrh%7%9%9:<<ay&)##r#   c                 <    U R                   u  pp4XS-  -   X$S-  -   4$ )z(Center of rectangle in data coordinates.r  )r  )r   rC  r@  rE  rB  s        r    r~   RectangleSelector.center  s*     !%BJb[ 000r#   c                 l    U R                   u  pp4[        XU-   /5      u  pV[        X"U-   /5      u  pxXVXx4$ )ze
Return (xmin, xmax, ymin, ymax) in data coordinates as defined by the
bounding box before rotation.
)r  r6  )	r   rC  r@  rE  rB  r  r  r  r  s	            r    r  RectangleSelector.extents  sC     !%Re,-
Rf-.
4%%r#   c                    U R                  U5        U R                  (       ar  U R                  R                  " U R                  6   U R
                  R                  " U R                  6   U R                  u  p#U R                  R                  U/U/5        U R                  U R                  5        U R                  5         g r   )r  r  rg  r  rf  r  rh  r~   ri  r  r  r  )r   r  rt   ru   s       r    r  r    s     	!  ))4<<8''):):;;;DA((!qc2'r#   c                 B    [         R                  " U R                  5      $ )us   
Rotation in degree in interval [-45°, 45°]. The rotation is limited in
range to keep the implementation simple.
)r   r  r`  r   s    r    r  RectangleSelector.rotation  s     zz$..))r#   c                 x    SU::  a4  US::  a-  [         R                  " U5      U l        U R                  U l        g g g )Ni-   )r   deg2radr`  r  )r   r  s     r    r  r    s3     %<ERKZZ.DN<<DL (<r#   c                 p   Uu  p#pE[        X#/5      u  pg[        XE/5      u  p[        U R                  R                  5       5      n
[        U R                  R                  5       5      n[	        U
S   U5      n[	        US   U5      n[        XzS   5      n[        XS   5      n	U R                  R                  U5        U R                  R                  U5        U R                  R                  Xv-
  5        U R                  R                  X-
  5        U R                  R                  U R                  5        g r  )r6  rW   r  r  rt  ro  r  r  r  r?  r<  	set_angler  )r   r  rC  rD  r@  rA  r  r  r  r  r#  r$  s               r    r  RectangleSelector._draw_shape  s     RH%
RH%
dgg&&()dgg&&()47D!47D!4a!4a!$$T*$$T*((5))$+6((7r#   c                    U R                   R                  UR                  UR                  5      u  p#U R                  R                  UR                  UR                  5      u  pEU R
                  R                  UR                  UR                  5      u  pgSU R                  ;   a  SU l        gXpR                  S-  :  a  SU l        gX0R                  :  aF  XPR                  :  a7  U R                  (       a  U R                  U5      (       a  SU l        gSU l        gX5:  a  U R                  U   U l        gU R                  U   U l        g)r  r  r  rP  N)rg  r  rt   ru   r  ri  r  r_  r  r  r  re  r  )r   rM   c_idxc_distr  r  m_idxm_dists           r    r  $RectangleSelector._set_active_handle  s     ,,44UWWeggF**22577EGGD++33EGGUWWET[[ "%Doo))"%Doo%&??*B&&4>>%+@+@&)#&*#_"&"4"4U";D #'"2"25"9Dr#   c                 <    U R                   R                  USS9S   $ r  r  rL   s     r    r  RectangleSelector._contains  r  r#   c                 t   [        U R                  S5      (       ap  U R                  R                  R	                  5       nUR                  U R                  R                  5       5      R                  u  p#[        R                  " X2/5      $ [        R                  " U R                  R                  5       5      $ )z
Return an array of shape (2, 5) containing the
x (``RectangleSelector.geometry[1, :]``) and
y (``RectangleSelector.geometry[0, :]``) data coordinates of the four
corners of the rectangle starting and ending in the top left corner.
	get_verts)r  r  rW   rq   rr   rs   r  rH  r   rU  get_data)r   xfmru   rt   s       r    geometryRectangleSelector.geometry
  s     4));77''##,,.C==!7!7!A!A!CDFFDA88QF##88D22;;=>>r#   )r_  rb  ra  ri  rg  re  r  r  r  r  r  r`  rw  r  r  r  r  r  r  r  rP  rQ  r  rR  r   )r7   r8   r9   r:   r;   r!   rR   r  rc  rT  r   rb  r  rd  r  rf  rh  r~   r  r  r  r  r  r  r  r<   r   r   s   @r    rN  rN  3  s;   :@&aUt"%)e&+%@& @&D - -;8.`M&^ 8 89) 
$ 
$ $ $ 1 1
 & & ^^
 
 * * __( (8$:8C ? ?r#   rN  ellipsec                   4    \ rS rSrSrS rS r\S 5       rSr	g)EllipseSelectori  aG  
Select an elliptical region of an Axes.

For the cursor to remain responsive you must keep a reference to it.

Press and release events triggered at the same coordinates outside the
selection will clear the selector, except when
``ignore_event_outside=True``.

%s

Examples
--------
:doc:`/gallery/widgets/rectangle_selector`
c                     [        SSS0UD6$ )Nrs  r(  F)r   r  s     r    rc  EllipseSelector._init_shape,  s    <U<e<<r#   c                 0   Uu  p#pE[        X#/5      u  pg[        XE/5      u  pX#U-
  S-  -   XEU-
  S-  -   /n
Xv-
  S-  nX-
  S-  nXR                  l        SU-  U R                  l        SU-  U R                  l        U R
                  U R                  l        g )Nr  rP  )r6  r  r~   rE  rB  r  r  )r   r  rC  rD  r@  rA  r  r  r  r  r~   r%  r  s                r    r  EllipseSelector._draw_shape/  s     RH%
RH%
R2~%r"WN':;[B[B(.%'(1u$()A%'+}}$r#   c                     U R                   R                  u  pU R                   R                  nU R                   R                  nXS-  -
  X$S-  -
  X44$ )Nr  )r  r~   rE  rB  )r   rt   ru   rE  rB  s        r    r  EllipseSelector._rect_bbox<  sP    %%,,&&,,''..2:~qB;==r#   r=   N)
r7   r8   r9   r:   r;   rc  r  rR   r  r<   r=   r#   r    r  r    s%    =5 > >r#   r  c                   N   ^  \ rS rSrSrSSSSS.U 4S jjjrS rS rS	 rS
r	U =r
$ )LassoSelectoriD  a  
Selection curve of an arbitrary shape.

For the selector to remain responsive you must keep a reference to it.

The selected path can be used in conjunction with `~.Path.contains_point`
to select data points from an image.

In contrast to `Lasso`, `LassoSelector` is written with an interface
similar to `RectangleSelector` and `SpanSelector`, and will continue to
interact with the Axes until disconnected.

Example usage::

    ax = plt.subplot()
    ax.plot(x, y)

    def onselect(verts):
        print(verts)
    lasso = LassoSelector(ax, onselect)

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
onselect : function, optional
    Whenever the lasso is released, the *onselect* function is called and
    passed the vertices of the selected path.
useblit : bool, default: True
    Whether to use blitting for faster drawing (if supported by the
    backend). See the tutorial :ref:`blitting`
    for details.
props : dict, optional
    Properties with which the line is drawn, see `.Line2D`
    for valid properties. Default values are defined in ``mpl.rcParams``.
button : `.MouseButton` or list of `.MouseButton`, optional
    The mouse buttons used for rectangle selection.  Default is ``None``,
    which corresponds to all buttons.
NT)r{   r  r1  c                   > [         TU ]  XX5S9  S U l        0 Ub  UO0 EU R                  SS.En[	        / / 40 UD6nU R
                  R                  U5        X`l        g )N)r{   r1  F)r  r(  )r   r!   rk  r{   r   rW   r5  r  )r   rW   r  r{   r  r1  r  r   s          r    r!   LassoSelector.__init__m  sm    wF

)ur
 	
 b"&&!%r#   c                 h    U R                  U5      /U l        U R                  R                  S5        g r	  )rJ  rk  r  r  rL   s     r    rT  LassoSelector._pressz  s)    nnU+,
**40r#   c                 &   U R                   bE  U R                   R                  U R                  U5      5        U R                  U R                   5        U R                  R                  / / /5        U R                  R                  S5        S U l         g r  )rk  rc   rJ  r  r  r  r  rL   s     r    r   LassoSelector._release~  sj    ::!JJdnnU34MM$**%''R1**51
r#   c                     U R                   c  g U R                   R                  U R                  U5      5        U R                  R	                  [        [        U R                   6 5      5        U R                  5         g r   )rk  rc   rJ  r  r  listr  r  rL   s     r    rb  LassoSelector._onmove  sU    ::

$../0''S$**-=(>?r#   )r  rk  r   )r7   r8   r9   r:   r;   r!   rT  r   rb  r<   r   r   s   @r    r  r  D  s2    &P&Td & &1 r#   r  c            	          ^  \ rS rSrSrSSSSSSSSS.U 4S jjjrS rS	 rS
 rS r	S r
\S 5       rS rS rS rS rS rS rS rS rS r\S 5       r\R.                  S 5       rS rSrU =r$ )PolygonSelectori  a5
  
Select a polygon region of an Axes.

Place vertices with each mouse click, and make the selection by completing
the polygon (clicking on the first vertex). Once drawn individual vertices
can be moved by clicking and dragging with the left mouse button, or
removed by clicking the right mouse button.

In addition, the following modifier keys can be used:

- Hold *ctrl* and click and drag a vertex to reposition it before the
  polygon has been completed.
- Hold the *shift* key and click and drag anywhere in the Axes to move
  all vertices.
- Press the *esc* key to start a new polygon.

For the selector to remain responsive you must keep a reference to it.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.

onselect : function, optional
    When a polygon is completed or modified after completion,
    the *onselect* function is called and passed a list of the vertices as
    ``(xdata, ydata)`` tuples.

useblit : bool, default: False
    Whether to use blitting for faster drawing (if supported by the
    backend). See the tutorial :ref:`blitting`
    for details.

props : dict, optional
    Properties with which the line is drawn, see `.Line2D` for valid properties.
    Default::

        dict(color='k', linestyle='-', linewidth=2, alpha=0.5)

handle_props : dict, optional
    Artist properties for the markers drawn at the vertices of the polygon.
    See the marker arguments in `.Line2D` for valid
    properties.  Default values are defined in ``mpl.rcParams`` except for
    the default value of ``markeredgecolor`` which will be the same as the
    ``color`` property in *props*.

grab_range : float, default: 10
    A vertex is selected (to complete the polygon or to move a vertex) if
    the mouse click is within *grab_range* pixels of the vertex.

draw_bounding_box : bool, optional
    If `True`, a bounding box will be drawn around the polygon selector
    once it is complete. This box can be used to move and resize the
    selector.

box_handle_props : dict, optional
    Properties to set for the box handles. See the documentation for the
    *handle_props* argument to `RectangleSelector` for more info.

box_props : dict, optional
    Properties to set for the box. See the documentation for the *props*
    argument to `RectangleSelector` for more info.

Examples
--------
:doc:`/gallery/widgets/polygon_selector_simple`
:doc:`/gallery/widgets/polygon_selector_demo`

Notes
-----
If only one point remains after removing points, the selector reverts to an
incomplete state and you can start drawing a new polygon from the existing
point.
NFr   )r{   r  r  r  draw_bounding_boxbox_handle_props	box_propsc          
      D  > [        SSSSSSSS9n
[        TU ]	  XUU
S9  S/U l        Uc  [        SS	S
SS9n0 UESU R                  0En[        / / 40 UD6=U l        nU R                  R                  U5        Uc  [        SUR                  SS5      S9nXPl
        [        U R                  / / U R                  U R                  S9U l        SU l        X`l        U R                  S5        Xpl        S U l        Uc  0 nU R                  R%                  U5      U l        Xl        g )Nr  r
  r	  r  )r  move_vertexmove_allr  r  r~   r  )r{   r  r  r'  -rP  r}   )r   r2  r  r  r  r   )rW  r1  )r{   r)  r  T)r  r   r!   _xysr{   r   r  rW   r5  r  r  r+  _polygon_handles_active_handle_idxr  r  	_draw_box_boxr  _box_handle_props
_box_props)r   rW   r  r{   r  r  r  r  r  r  r  r  r   s               r    r!   PolygonSelector.__init__  sB    #y,3:J*:*:*:	<
 	w-@ 	 	B H	=scQcJE353*dll3(.r2(?(??05		'30GIL) +DGGR48LL9=9K9K!M #%$*	#!!%!3!3!:!:;K!L#r#   c                 6    U R                   R                  5       $ r   )r  r  r   s    r    	_get_bboxPolygonSelector._get_bbox  s    %%..00r#   c           	         [        U R                  U R                  U R                  U R                  U R
                  SS9U l        U R                  R                  R                  S5        U R                  R                  SU R                  5        U R                  5         SU R                  l        SU R                  l        U R                  5         g )NT)r{   r  r  r  r  r  r   F)rN  rW   r{   r  r  r  r  r  r  rf   _scale_polygon_update_boxrb  r  _draw_polygonr   s    r    _add_boxPolygonSelector._add_box  s    %dgg.2ll15373I3I,0OO268	 			&&**84		 5t7J7JK %*		!)-		&r#   c                 d    U R                   b#  U R                   R                  S5        S U l         g g r  )r  r  r   s    r    _remove_boxPolygonSelector._remove_box  s*    99 II!!%(DI !r#   c                     U R                   bi  U R                  5       nUR                  UR                  UR                  UR
                  /U R                   l        U R                   R                  U l        g g r   )r  r  rC  rD  r@  rA  r  _old_box_extents)r   r   s     r    r  PolygonSelector._update_box   sT    99 >>#D!%$''477DGG DDII$(II$5$5D!	 !r#   c                    U R                   (       d  gU R                  U R                  R                  :X  a  gU R                  R                  u  p#pEU R                  5       n[        R                  " 5       R                  UR                  * UR                  * 5      R                  SUR                  -  SUR                  -  5      R                  XE5      R                  X#5      nUR                  [        R                   " U R"                  5      5       VV	s/ s H  u  pX4PM
     n
nn	/ U
QU
S   PU l        U R'                  5         U R                  R                  U l        gs  sn	nf )z
Scale the polygon selector points when the bounding box is moved or
scaled.

This is set as a callback on the bounding box RectangleSelector.
Nr   r   )r  r  r  r  r  r  r   r   r  rC  r@  r  rE  rB  rs   r   rU  rk  r  r  )r   rM   rD  rA  w1h1old_bboxtrt   ru   	new_vertss              r    r  PolygonSelector._scale_polygon(  s    ((  DII$5$55 -->>#  "ix{{l3eA&HOO(;<eBmi	 	
 )*BHHTZZ4H(IJ(IaV(I	J.i.1.	 $		 1 1 Ks   E"c                 .    U R                   R                  $ r   )r  r#  r   s    r    r   PolygonSelector._handles_artistsD  s    $$,,,r#   c                    [        U R                  5      S:  a  U R                  (       a}  US[        U R                  5      S-
  4;   a_  U R                  R                  S5        U R                  R                  S5        U R                  R	                  U R                  S   5        OU R                  R                  U5        [        U R                  5      S::  a  SU l        U R                  5         gg)zRemove vertex with index i.rP  r   r   r  FN)r  r  r  r  rc   r  )r   r  s     r    _remove_vertexPolygonSelector._remove_vertexH  s    		NQ))aTYY!+,, IIMM!IIMM" IITYYq\*IIMM!tyy>Q ).D%	 r#   c                 D   U R                   (       d  SU R                  ;   a`  [        U R                  5      S:  aG  U R                  R                  UR                  UR                  5      u  p#X0R                  :  a  X l	        U R                  R                  5       U l        g)rW  r  r   N)r  r  r  r  r  r  rt   ru   r  r  rM  _xys_at_press)r   rM   h_idxh_dists       r    rT  PolygonSelector._press\  so     &&-4;;*F		NQ& 1199%''577KME'*/' "YY^^-r#   c                    U R                   S:  aC  UR                  S:X  a+  U R                  U R                   5        U R                  5         SU l         O[	        U R
                  5      S:  aV  U R
                  S   U R
                  S   :X  a6  SU l        U R                  (       a  U R                  c  U R                  5         O\U R                  (       dK  SU R                  ;  a;  SU R                  ;  a+  U R
                  R                  SU R                  U5      5        U R                  (       a  U R                  U R                  5        gg)r^  r   rg  r  TNr  r  )r  r1  r   r  r  r  r  r  r  r  r  insertrv   r  rk  rL   s     r    r   PolygonSelector._releaseh  s     ""a'||q ##D$;$;<""$&(D# ^aDIIbMTYYq\$A(,D%~~$))"3 ++DKK/t{{2IIR!6!6u!=>$$MM$**% %r#   c                 f   U R                  U5      (       ay  U R                  R                  R                  U 5      (       dN  U R                  (       a=  [
        R                  [
        R                  4U R                  S'   U R                  5         gU R                  U5      nU R                  U5        g)ra  r  FT)
rN   r^   r  r&   r  r   nanr  rN  rb  rL   s     r    r  PolygonSelector.onmove  s~     ;;u;;))33D99dii!# 0		"""$ %%e,ELLr#   c                 ^   U R                   S:  aa  U R                   nU R                  U5      U R                  U'   US:X  a/  U R                  (       a  U R                  U5      U R                  S'   GOSU R                  ;   a  U R
                  (       a  U R                  U5      u  p4X0R
                  R                  -
  nX@R
                  R                  -
  n[        [        U R                  5      5       H)  nU R                  U   u  pX-   X-   4U R                  U'   M+     OU R                  (       d   SU R                  ;   d  SU R                  ;   a  gU R                  R                  5       R                  U R                  S   5      u  p[        R                  " XR                   -
  XR"                  -
  5      n[        U R                  5      S:  a,  XR$                  :  a  U R                  S   U R                  S'   OU R                  U5      U R                  S'   U R'                  5         g)re  r   r  r  r  Nrg  )r  rv   r  r  r  r  ro   rp   r  r  r  r  get_transformrs   r   rG  rt   ru   r  r  )r   rM   r~  ro   rp   r  r  r'  
x_at_press
y_at_pressrC  r@  v0_dists                r    rb  PolygonSelector._onmove  s    ""a'))C!2259DIIcN axD55 $ 5 5e <		" 4;;&4+;+;007LE))///B))///B3tyy>*)-););A)>&
)
?		! +
 ''$++-t{{1J &&446@@1N BhhrGG|R''\:G499~!g&? $		!		" $ 5 5e <		"r#   c                     U R                   (       dL  SU R                  ;   d  SU R                  ;   a+  U R                  R                  5         U R	                  5         ggg)zKey press event handler.r  r  N)r  r  r  r  r  rL   s     r    ro  PolygonSelector._on_key_press  sH     ))"dkk14;;.IIMMO  / *r#   c                 4   U R                   (       d  UR                  U R                  R                  S5      :X  d)  UR                  U R                  R                  S5      :X  a;  U R                  R                  U R                  U5      5        U R                  5         gUR                  U R                  R                  S5      :X  aQ  U R                  U5      nU R                  U5      /U l        SU l         U R                  5         U R                  S5        gg)ry  r  r  r  FTN)r  rU  r  r  r  rc   rv   r  rN  r  r  rL   s     r    rv  PolygonSelector._on_key_release  s     ))d77;;MJJII!:!:!>!>z!JJIIT2259: YY$3377@@%%e,E..u56DI(-D%T" Ar#   c                    U R                   (       a  [        U R                   6 O/ / 4u  pU R                  R                  X5        U R	                  5         U R
                  (       d9  [        U R                   5      S:  aC  U R                   S   U R                   S   :X  a#  U R                  R                  USS USS 5        gU R                  R                  X5        g)z>Redraw the polygon based on new vertex positions, no update().rg  r  r   N)r  r  r  r  r  r  r  r  )r   xsr  s      r    _draw_polygon_without_update,PolygonSelector._draw_polygon_without_update  s    $(IIdiiB8''/ %%		NQ&		"15!!**2cr7BsG<!!**22r#   c                 D    U R                  5         U R                  5         g)z5Redraw the polygon based on the new vertex positions.N)r  r  r   s    r    r  PolygonSelector._draw_polygon  s    ))+r#   c                      U R                   SS $ )z4The polygon vertices, as a list of ``(x, y)`` pairs.Nr  )r  r   s    r    rk  PolygonSelector.verts  s     yy"~r#   c                     / UQUS   PU l         SU l        U R                  S5        U R                  (       a  U R                  c  U R                  5         U R                  5         g)zz
Set the polygon vertices.

This will remove any preexisting vertices, creating a complete polygon
with the new vertices.
r   TN)r  r  r  r  r  r  r  )r   xyss     r    rk  r    sR     #cN3q6N	$(!>>dii/MMOr#   c                 B    SU l         S/U l        U R                  5         g )NFr  )r  r  r  r   s    r    r  %PolygonSelector._clear_without_update  s    $)!H	))+r#   )r  r  r  r  r  r  r  r  r  r  r  r  r  r   )r7   r8   r9   r:   r;   r!   r  r  r  r  r  rR   r  r   rT  r   r  rb  ro  rv  r  r  rk  r  r  r<   r   r   s   @r    r  r    s    IV+$U$2#(4+$ +$Z1 
628 - -(
.&0$%N!#$3
   \\ , ,r#   r  c                   B   ^  \ rS rSrSrSSS.U 4S jjrS rS rS	rU =r	$ )
Lassoi  a  
Selection curve of an arbitrary shape.

The selected path can be used in conjunction with
`~matplotlib.path.Path.contains_point` to select data points from an image.

Unlike `LassoSelector`, this must be initialized with a starting
point *xy*, and the `Lasso` events are destroyed upon release.

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The parent Axes for the widget.
xy : (float, float)
    Coordinates of the start of the lasso.
callback : callable
    Whenever the lasso is released, the *callback* function is called and
    passed the vertices of the selected path.
useblit : bool, default: True
    Whether to use blitting for faster drawing (if supported by the
    backend). See the tutorial :ref:`blitting`
    for details.
props: dict, optional
    Lasso line properties. See `.Line2D` for valid properties.
    Default *props* are::

        {'linestyle' : '-', 'color' : 'black', 'lw' : 2}

    .. versionadded:: 3.9
TN)r{   r  c                2  > [         T	U ]  U5        U=(       a    U R                  R                  U l        U R                  (       a4  U R                  R                  U R                  R                  5      U l        SSSS.nUb  UR                  U5        Uu  pxXx4/U l
        [        U/U/40 UD6U l        U R                  R                  U R                  5        X0l        U R                  SU R                   5        U R                  SU R"                  5        g )Nr  r  rP  )r2  r   r	  r   r   )r   r!   r^   r   r{   r  rW   r   r  r  rk  r   r  r5  rd   rf   	onreleaser  )
r   rW   rh  rd   r{   r  stylert   ru   r   s
            r    r!   Lasso.__init__"  s    <4;;#<#<<<"kk88FDO!G1=LLfX
A3-u-	# 14>>B0$++>r#   c                 j   U R                  U5      (       a  g U R                  bx  U R                  R                  U R                  U5      5        [	        U R                  5      S:  a  U R                  U R                  5        U R                  R                  5         S U l        U R                  5         g )NrP  )	rN   rk  rc   rv   r  rd   r  r  rk   rL   s     r    r&  Lasso.onrelease6  s~    ;;u::!JJd33E:;4::"djj)II
 r#   c                    U R                  U5      (       d@  U R                  b3  UR                  S:w  d#  U R                  R	                  U5      S   (       d  g U R                  R                  U R                  U5      5        U R                  R                  [        [        U R                  6 5      5        U R                  (       az  U R                  R                  U R                  5        U R                  R                  U R                  5        U R                  R!                  U R                  R"                  5        g U R                  R%                  5         g )Nr   r   )rN   rk  r1  rW   r   rc   rv   r  r  r  r  r{   r^   r  r  r   r   r   rC  rL   s     r    r  Lasso.onmoveA  s    KK::%<<1$ww''.q1

$//67		4TZZ 012<<KK&&t7GG		*KKTWW\\*KK!!#r#   )r  rd   r  r{   rk  )
r7   r8   r9   r:   r;   r!   r&  r  r<   r   r   s   @r    r$  r$    s(    < 59 ? ?(	!$ $r#   r$  ):r;   
contextlibr   rM  r  numbersr   r   r   numpyr   
matplotlibr1  r  r   r	   r
   r   r   r   r   r  r   r   linesr   patchesr   r   r   r   r   r   r?   rT   ry   r   r   rN  r  r  r  r  r  r  r  r  r  r  r+  '_RECTANGLESELECTOR_PARAMETERS_DOCSTRINGSubstitutionrR  rN  r  r  r  r$  r=   r#   r    <module>r5     s  	 !   $   2 2 2  0 0 6#' #'L 83Q 3Qld(Z d(NK' K'\GIZ GITuI* uIp@
j(: j(Z	A(j A(HD(: D(NE&& E&PT$Z T$nB#& B#J_"j _"D[? [|k" k"\>* >*DT (p @HH{$ %b? b?%b?J @HHy" #%>' %>#%>PHO HVq,o q,hL$J L$r#   