rL iT&dZddlmZddlZddlZddlmZmZddlmZddl Z ddl Z ddl mZmZmZmZmZmZmZmZmZddlmZdd lmZmZmZdd lmZmZGd d Z Gd dZ!Gdde!Z"Gdde"Z#Gdde"Z$Gdde$Z%Gdde$Z&dZ'Gdde"Z(Gdde"Z)Gdde"Z*Gd d!e!Z+Gd"d#e"Z,Gd$d%e!Z-Gd&d'e"Z.Gd(d)e.Z/Gd*d+Z0Gd,d-Z1d.Z2ejfe2jid/d0Gd1d2e.Z5ejfe2jid/d3Gd4d5e5Z6Gd6d7e.Z7Gd8d9e.Z8Gd:d;e"Z9y)zAxesWidget.xs477#5#54#5#@#G#Gr!cr|jj||}|jj|y)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)rO mpl_connectrJappend)rrAcallbackcids r connect_eventzAxesWidget.connect_eventzs,kk%%eX6 #r!c\|jD]}|jj|y)z-Disconnect all events created by this widget.N)rJrOmpl_disconnect)rcs rdisconnect_eventszAxesWidget.disconnect_eventss' *A KK & &q ) *r!c|j|jur|j|jfS|jjj j |j|jfS)z8Return *event*'s data coordinates in this widget's Axes.) inaxesrIxdataydata transDatainverted transformxyr@s r_get_data_coordszAxesWidget._get_data_coordss]/4lldgg.Eekk* QWW&&//1;;UWWegg.s U r!rzconnectrrs `r on_clickedzButton.on_clickeds &&y2KLLr!c:|jj|y)z6Remove the callback function with connection id *cid*.Nrz disconnectrrUs rrzButton.disconnect ""3'r!)Nz0.85z0.95) r0r1r2r3r r{r|r}rr __classcell__rs@rrfrfs8$)-*0+%=A+%Z- 6 'M(r!rfc4eZdZdZfdZdZdZdZxZS) SliderBasez 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 |jdk(r tdt | |t j ddg|||_||_||_||_ ||_ | |_ d|_ ||_ |dk(r |j||f|j} n|j!||f|j"} | j%|_t)|j&t*j,s4t+j,|_|j&j/| |j&j1d|j&j3d|j5|j7d|j9d|j:|j9d |j:|r|j9d |j:t=j>d g |_ y) N3dz"Sliders cannot be added to 3D Axes horizontalvertical) orientationFTrprqrrchangedrn)!namer%rsr r check_in_listr closedmin closedmaxvalminvalmaxvalstep drag_activevalfmtset_ylimyaxisset_xlimxaxisget_major_formatter_fmt isinstancerScalarFormatterset_axis set_useOffsetset_useMathText set_axis_offr~rV_updater ryrz) rrIrrrrrrdraggingraxisrs rr zSliderBase.__init__s 77d?AB B  L*5;O&""     * $ KK( )88D KK( )88D,,. $))V%;%;<..0DI II  t $ & !!$'   /> 14<<@    4dll C00)Er!ct|jtrA|jt ||jz |jz |jzz}|S|jtt j |j}|jdk7rtd|j|t jt j||z }|S)z?Return *val* coerced to closest number in the ``valstep`` grid.rz&valstep must have 1 dimension but has ) rrrrroundnp asanyarrayndimr%argminabs)rvalrs r_stepped_valuezSliderBase._stepped_value*s dllF +;;C$++-=>MNC \\ %mmDLL1G||q  DJ774dll7.C-/\\5=7=#?DL Wm s9Kc|j|}||jkr|jsy|j}n(||jk\r|jsy|j}|j <||j j kr#|jsy|j j }|j<||jj k\r#|jsy|jj }|S)z&Makes sure *val* is with given bounds.N)rrrrrrrrrrs rrzSlider._value_in_boundss!!#& $++ >>++C DKK >>++C >> %#1C1C*C>>..$$C >> %#1C1C*C>>..$$C r!c|j|s|jdk7ry|jdk(rJ|jj |dr,d|_|j j|j|j sy|jdk(s-|jdk(rK|jj |ds-d|_|j j|jy|j|\}}|j|jdk(r|n|}|d|jfvr|j|yy zUpdate the slider position.rNrprTrqFr)rBbuttonrrIrrrOrrrdrrrr)rrAr]r^rs rrzSlider._update s ;;u !2  ::- -$''2B2B52I!2L#D  LL # #DGG ,  JJ0 033DGG.P d3ir!rrs `r on_changedzSlider.on_changedA&&y2GHHr!) r0r1r2r3r rrrrr$rrs@rrrIsI >A44$)S(t Zx00.4*Ir!rc zeZdZdZdddddddddd fd ZdZd Zd Zd Zd Z d Z dZ dZ dZ dZdZxZS) RangeSlidera 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. NTrr) rrrrrrrrrc tt||| |||||| | ||f|_|)||z }tj||dzz||dzzg}n|j |}||_||_dddd}| in| } i|| jDcic] \}}d|| }}}| d k(retd d d |j| |_ |j|j|jjd}d |dg}d |dg}ndtddd |j| |_ |j|j|jjd}|dd g}|dd g}ttj dd gfi||_|j$||j"j'|d|j"j)_|jj|j"|jj-|j.g|di|ddid|j.g|di|ddidg|_| d k(r\|j3d d||jdd|_|j3d d|j7||jdd|_n[|j3dd ||jdd|_|j3dd |j7||jdd|_d|_|j=|ycc}}w) 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.). Nrrrrrrrrrrirgrid)whichrrrdr'rFrrrjrrrrr)rsr rrarrayrrrrrurrrIget_yaxis_transformget_xaxis_transformrzerosr_update_selection_poly set_transformget_path_interpolation_steps_request_autoscale_viewr_handlesrrvrr_active_handler)rrIrvrrrrrrrrrrrrextentrrrr poly_transform handleXY_1 handleXY_2rs rr zRangeSlider.__init__bsd [)Y7 DF# ?f_Fhh$ 6 &$ 6 89G++G4G !(ubI)1r| (D8(D|(D(J(J(L $1fQCL!O   * $""a,,%DJ LL $!WW88v8FNgaj)Jgaj)J"!R,,%DJ LL $!WW88v8FN!!*b)J!!*b)JBHHaV,77 ###W- /47 1 $))$ '') BGG          BGG             * $,,"*$, !DJ77 W%,,"'$, #DL,,"*$+ !DJ77 W%,,"*$* #DL# Wg sL4c|jj}|jdk(r"d|fx|d<|d<d|f|d<d|f|d<d|f|d<y |dfx|d<|d<|df|d<|df|d<|df|d<y ) zx Update the vertices of the *self.poly* slider in-place to cover the data range *vmin*, *vmax*. rrrrrr)N)rxyr)rvminvmaxvertss rr2z"RangeSlider._update_selection_polys    z )"%t) +E!HuQxDyE!HDyE!HDyE!H"&) +E!HuQxSyE!HSyE!HSyE!Hr!c||jkr'|js|jdS|j}||jdkDr|jd}|j|S)z;Ensure the new min value is between valmin and self.val[1].rr)rrrrrmins r_min_in_boundszRangeSlider._min_in_bounds/sZ $++ >>xx{"++C ! ((1+C""3''r!c||jk\r'|js|jdS|j}||jdkr|jd}|j|S)z;Ensure the new max value is between valmax and self.val[0].rr)rrrrrmaxs r_max_in_boundszRangeSlider._max_in_bounds:sZ $++ >>xx{"++C $((1+ ((1+C""3''r!cR|j|d|j|dfS)z#Clip min, max values to the bounds.rr)rGrK)rvalss rrzRangeSlider._value_in_boundsEs+##DG,d.A.A$q'.JKKr!ctjtj|j|z }|dk(r#|j |}|j |n"|j |}|j||jrI|jdk(r|jj|gy|jj|gyy)z2Update the slider value based on a given position.rrN) rrrrrGset_minrKset_maxr8rrr)rposidxrs r_update_val_from_posz RangeSlider._update_val_from_posIsiitxx#~./ !8%%c*C LL %%c*C LL    :-##--se4##--se4 r!c |j|s|jdk7ry|jdk(rJ|jj |dr,d|_|j j|j|j sy|jdk(s-|jdk(rR|jj |ds4d|_|j j|jd|_ y|j|\}}tjtj|jdk(r.|jDcgc]}|j!d|z c}n-|jDcgc]}|j#d|z c}}|j|}||jur||_ |j%|jdk(r|y|ycc}wcc}wr)rBrrrIrrrOrrr8rdrrrrr7 get_xdata get_ydatarS)rrAr]r^h handle_indexhandles rrzRangeSlider._updateXs ;;u !2  ::- -$''2B2B52I!2L#D  LL # #DGG ,  JJ0 033DGG =s G) 5G. cd|j)d|j|dzd|j|dzdS|jj|jg||j\}}}}||jj z }||jj z }d|d|dS)r(rz, r)r)rrrs1s2s rrzRangeSlider._formatzs ;; "t{{SV+,Bt{{SV/C.DAF F99110s0DKK0LAr2q $))&&( (B $))&&( (Brd"RD? "r!cD|j||jdfy)zx Set the lower value of the slider to *min*. Parameters ---------- min : float rNrrrEs rrOzRangeSlider.set_mins c488A;'(r!cD|j|jd|fy)zx Set the lower value of the slider to *max*. Parameters ---------- max : float rNr`rIs rrPzRangeSlider.set_maxs dhhqk3'(r!c:tj|}tjd||j|j f|_|j|\}}|j|||jdk(r?|jdj|g|jdj|gn>|jdj|g|jdj|g|jj|j||f|j r4|j"j%dj&j)||f|_|j*r|j,j/d||fy y ) z~ Set slider value to *val*. Parameters ---------- val : tuple or array-like of float )r))rrrrTrLrN)rsortr check_shaperrrrr2rr7rrrrrrCrIrNrOrrDrzr)rrrArBs rrzRangeSlider.set_valsDggcl 3'KK-**3/ d ##D$/   z ) MM!  & &v . MM!  & &v . MM!  & &v . MM!  & &v . dllD$<89 ;; GG  D  ) 0 0 : : <$< == OO # #Id| < r!cB|jjdfdS)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*). rc|Srr4r"s rrPz(RangeSlider.on_changed..r#r!rrs `rr$zRangeSlider.on_changedr%r!)r0r1r2r3r r2rGrKrrSrrrOrPrr$rrs@rr'r'Ssg * vp!* ( (L 5 XD #))=:Ir!r'ctj|tj}|rt di|St j iSNr4)r normalize_kwargsmtextTextr itertoolsrepeatpropss r_expand_text_propsrps;  " "5%** 5E %?6?E? ?9+;+;B+??r!czeZdZdZddddddfd ZdZdZdZd Zd Z dd Z d Z d Z dZ dZdZdZxZS) CheckButtonsa 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)rg label_props frame_props check_propsc t||tjtdf||||j g|j g|jd|dgt|z}|xr|jj|_ d|_ tjddt|dzdd}t|}t!|||D cgc])\} } } |j"d| | f|j$d d d | +c} } } |_tj(|j&D cgc]} | j+c} dz } | dzdd t-j.|t0j2d |j$d}|j5d|j7dd|j5d|j9dd|j:dgt|z|fi||_d| dzdt-j.|t0j2d|j$|jd}|j5d|j9dd|j:dgt|z|fi||_|jA||jCd|jD|jr|jCd|jFt-jHdg|_%ycc} } } wcc} w)a' 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 of lists, optional Dictionary of `.Text` properties to be used for the labels. Each dictionary value should be a list of at least a single element. If the list is of length M, its values are cycled such that the Nth label gets the (N mod M) property. .. 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)rsrtruFrrr)rrrjrarlrk)r linewidthr)rrarrnonerblack333333?)ryrrbrraanimatedrp draw_eventrmrn)&rsr rcheck_isinstancedictrrr~lenrOrwrx _backgroundrlinspacerpziprrulabelsr. get_fontsizer rir PathCollection setdefaultgetpopscatter_frames_checks _init_statusrV_clicked_clearryrz)rrIractivesrgrsrtruysrcrvror text_sizers rr zCheckButtons.__init__sP  tTl *5; P b b  ?gF +G=DKK$=$=  [[As6{1} -a 3(5 $'r6;#? AA 5% BGGD!U bll(.(  A HHdkkJdd//1JKaO A $$[+2L2LM    {KOOGV,LM{KOOGW,MN!rzz4&3r7"2BF+F A $$[+2L2LM    {KOOGW,MN!rzz4&3r7"2BF+F  '" /? ==   |T[[ 900)EIA Ks .K71K>c|j|s|jjry|jj|jj |_|jj|jyz,Internal event handler to clear the buttons.N) rBrO is_savingcopy_from_bboxrIrrrrr@s rrzCheckButtons._clearAsU ;;u !6!6!8 ;;55dggllC DLL)r!cv|j|s-|jdk7s|jj|dsyg|jj|ddt |j Dcgc]\}}|j|ds|c}}}|r|jjj|jj}|j||j|jf||z dzjdjyycc}}wNrrindr)rw)rBrrIrr enumeraterget_offset_transformra get_offsetsr;rbrcsumrrrAiridxscoordss rrzCheckButtons._clickedHs ;;u !2$'':J:J5:QRS:T S \\ " "5 )! ,U 3S(5 QGAtu9Ma9Pa QS \\668BB ((*,F OO)F4L8Q>CCBGNNPQ S R :D5D5ctjt|t|}t |j |D]\}}|j |y)a$ Set properties of the `.Text` labels. .. versionadded:: 3.7 Parameters ---------- props : dict Dictionary of `.Text` properties to be used for the labels. Same format as label_props argument of :class:`CheckButtons`. rnNrrrrprrupdaterrorprops rset_label_propszCheckButtons.set_label_propsTH d%0"5)dkk51 JD$ KK  r!ctjt|d|vr;tj|j dt |j|d<|jj|y)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. rnrsizesN) rrrr broadcast_torrrrrrros rset_frame_propszCheckButtons.set_frame_propsesR d%0 %<__UYYs^S=MNE'N E"r!c0tjt|d|vr;tj|j dt |j|d<|j}|jj||j|y)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. rnrrN) rrrrrrrr get_statusrrr)rrors rset_check_propszCheckButtons.set_check_propsvsl d%0 %<__UYYs^S=MNE'N//# E" '"r!c|tt|jvrtd|t j t df|tjd}|jj}|tj|||}|r|j|n|||<|jj||jr|jr|j %|j"j%|j |j&j)|j|j"j+|j&j,n|j"j/|j0r8|j2j5d|j|j7yy)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. zInvalid CheckButton index: Nstaterzrm)rangerrr%rrboolr to_rgbarrr_active_check_colorsrrCrxrrOrestore_regionrIrrrrrDrzrget_text)rindexr invisible facecolorss rr;zCheckButtons.set_activesL, c$++./ /:5'BC C tTl%8NN6* \\//1 =%%j&7CE@ED55e<9 5 "":. ;;}}##/KK..t/?/?@##DLL1   .   " == OO # #It{{5/A/J/J/L M r!cj|jj|_t|jdk(r0t j |jt|d|_|jj t|j|Dcgc] \}}|r|nd c}}ycc}}w)a 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. rrrrzN)rrrrrrmrr)rrecr:s rrzCheckButtons._init_statuss%)LL$>$>$@! t(( )Q .(* $2K2K25g,Q)HD % """4#<# Any Return values may exist, but are ignored. Returns ------- A connection id, which can be used to disconnect the callback. rmc|Srr4rrs rrPz)CheckButtons.on_clicked..s tDzr!rrs `rrzCheckButtons.on_clickeds&&&y2IJJr!c:|jj|yz-Remove the observer with connection id *cid*.Nrrs rrzCheckButtons.disconnectrr!r)r0r1r2r3r rrrrrr;rrrrrrrrs@rrrrrsa ^FD!t^F@* S"#"#(,N\I 5"< K*(r!rrceZdZdZddddddfd ZedZd Zd Zd Z d Z d Z dZ dZ dZdZdZdZdZxZS)TextBoxaP 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.951g{Gz?r)rr label_pad textalignmentc ft||tjdddd||_|j | d||j dd|_|jj |jd||jj d|d |_ tjd d g |_ |jddd |ggd|_|jdddd ddt j"j%|_|j)d|j*|j)d|j,|j)d|j.|j)d|j0|j)d|j2||_||_d |_y)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. 皙?rigffffff?)rrjr)rrjrrF)rarkrl parse_mathchangesubmitrnrr)xlimylimnavigaterxticksyticksrrr)visiblerrrarprqrrkey_press_event resize_eventN)rsr r check_getitem_text_positionrrurvrI text_dispr ryrzset cursor_indexvlinesmplrIdentityTransformcursorrVr{r|r} _keypress_resizerrcapturekeystrokes) rrIrvinitialrrrrrs rr zTextBox.__init__s* "00S4 8')WW JUbll&GE    g9J9J&M&  00(H9MN feb  " ii1aca*-..*J*J*L N  /= 14==A 0$,,? ,dnn= >4<<8 $!&r!c6|jjSr)rrrs rrz TextBox.textTs~~&&((r!c|jjd}|j|jj |j j }|d|j}|j j}|j j|xsd|j j}|j|jk(rE|xj|jdz zc_ |xj|jdz z c_ n2|s|j|_n|j|jz|_|j j#|j|jf|j|jfggd|j j||jj y)NTrL,r))segmentsr)rIrN _get_rendererrOrrrrget_window_extentry0y1heightx0x1widthrr)rfigr widthtextbb_text bb_widthtexts r _rendercursorzTextBox._rendercursorXs]gg  d +     & JJOO ~~&&(+$++, ..224  0S1~~779 :: # JJ,--1 1J JJ,--1 1J GJ l&8&88GJ  GJJ/'**gjj1IJK   % r!c|j|ry|jj|jk7ry|jj |jyr)rBrOrrIrr@s rr|zTextBox._release{s@ ;;u   << % % 0  ""477+r!c>|j|ry|jr|j}|j}t |dk(r9|d|j |z||j dz}|xj dz c_n|dk(r.|j t |k7r|xj dz c_n|dk(r%|j dk7r|xj dzc_n|dk(rd|_n|dk(rt ||_n|dk(rG|j dk7r|d|j dz ||j dz}|xj dzc_nI|dk(rD|j t |jk7r"|d|j ||j dzdz}|j j||j|jrR|jjd |j|d vr'|jjd |jyyyy) Nrrrrhomeend backspacedeleter)enterreturnr) rBrkeyrrrrrrrDrzr)rrArrs rrzTextBox._keypresss ;;u    ! !))C99D3x1}/d//036T../01!!Q&!$$D 1%%*%$$)%%*%$%!$'I! #$$) !7$"3"3a"78 !2!2!345D%%*%$$DII6 !3$"3"34 !2!2Q!6!789D NN # #D )    }}''$))<--OO++Hdii@.9 "r!cBt|}|j|k(ry|jj||j |j rM|j jd|j|j jd|jyy)Nrr)strrrrrrDrzr)rrnewvals rrzTextBox.set_valstS 99   '  == OO # #Hdii 8 OO # #Hdii 8 r!c 4d|_t}|j|_t |j j djjdd}|8|j||j|jj|ytj5|jtj tj"Dcic]}|j%ds|gc}dddycc}w#1swYyxYw)NTrL toolmanagerzkeymap.)rrclose_on_stop_typinggetattrrIrNrOmanager keypresslockrTr*r'suppress_matplotlib_deprecation_warning enter_contextr rc_contextrcParams startswith)rstackrrs r begin_typingzTextBox.begin_typings!% ${{ GG  D  ) 0 0 8 8-O  "  $ $T * NN;33;;T B==? O##CNN$'LLLqALL4KQUL%NO O OL O Os$,-DD 0D 5 D DDcl|jr|jd|_d}nd}d|_|jjd|jj dj j|r4|jr'|jjd|jyyy)NTFrLr) rrrrrIrNrOrrDrzrr)r notifysubmits r stop_typingzTextBox.stop_typings  ! !  "#'D L L!& & %,,113 DMM OO # #Hdii 8*. d4jr!rrs `ron_text_changezTextBox.on_text_changes &&x1HIIr!cB|jjdfdS)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. rc|Srr4rs rrPz#TextBox.on_submit..r)r!rrs `r on_submitzTextBox.on_submits&&x1HIIr!c:|jj|yrrrs rrzTextBox.disconnectrr!))r0r1r2r3r rErrr|rrrr"r{rr}r*r-rrrs@rrrss,:'%:'x))!F,"AH9O* 9 <JJ(r!rceZdZdZdddddfd ZdZdZdZd Ze d Z e jd Z d Z d Z dZdZxZS) RadioButtonsa? 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)rgrs radio_propsc t||tjtdf||t j |tj}|d|vrtjdnd}||_ ||_ |||_ ||_ |jg|jg|j!dt#j$ddt'|d zdd }|xr|j(j*|_d|_t1|}t3|||D cgc])\} } } |j4d | | f|j6d d d| +c} } } |_t#j:|j8D cgc]} | j=c} d z } d| d zi|d|j6|j,d}|j?d|jAdd|j?d|jCd||jDdgt'|z|fi||_#|jFjI|_%t'|jJdk(r0t#jL|jJt'|d|_%|jFjOtQ|jJDcgc]\}}||k(r|ndc}}|jSd|jT|j,r|jSd|jVt jXdg|_-ycc} } } wcc} wcc}}w)a 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 of lists, optional Dictionary of `.Text` properties to be used for the labels. Each dictionary value should be a list of at least a single element. If the list is of length M, its values are cycled such that the Nth label gets the (N mod M) property. .. 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)rsr2rzBoth the *activecolor* parameter and the *facecolor* key in the *radio_props* parameter has been specified. *activecolor* will be ignored.blueFrrr)rwrrrjrxrr'r}rrr{r|rrzrprrmrn).rsr rrrr rir r warn_external _activecolor_initial_activevalue_selectedindex_selectedrrr~rrrrOrwrxrrprrrurr.rrrrr_buttonsr_active_colorsrmrrrVrrryrz)rrIrr: activecolorrgrsr2rrcrvrorrrrs rr zRadioButtons.__init__s R  tTl *5 7,,[-8-G-GI  "k)""56 !K'%$Vn$ b b  [[As6{Q /" 5=DKK$=$= (5 $'r6;#? AA 5% BGGD!U bll(.(  A HHdkkJdd//1JKaO  A     {KOOGW,MN{*w D F" C53r7?BF+F #mm99; t"" #q ("$))D,?,?V12#4D  ###,T-@-@#A CKK[V 3 C D /? ==   |T[[ 900)ECA K* Cs+.L>MM c|j|s|jjry|jj|jj |_|jj|jyr) rBrOrrrIrrrr:r@s rrzRadioButtons._clearsU ;;u !6!6!8 ;;55dggllC DMM*r!cv|j|s-|jdk7s|jj|dsyg|jj|ddt |j Dcgc]\}}|j|ds|c}}}|r|jjj|jj}|j||j|jf||z dzjdjyycc}}wr)rBrrIrr:rrrrarr;rbrcrrrs rrzRadioButtons._clickeds ;;u !2$'':J:J5:QRS:T S ]] # #E *1 -e 4S(5 QGAtu9Ma9Pa QS ]]779CC ))+-F OO)F4L8Q>CCBGNNPQ S Rrctjt|t|}t |j |D]\}}|j |y)a$ Set properties of the `.Text` labels. .. versionadded:: 3.7 Parameters ---------- props : dict Dictionary of `.Text` properties to be used for the labels. Same format as label_props argument of :class:`RadioButtons`. rnNrrs rrzRadioButtons.set_label_propsrr!ctjt|d|vr;tj|j dt |j|d<|jj||jj|_ t |jdk(r:tj|jt |jd|_ |jjt|j|jDcgc]&\}}|j|j k(r|nd(c}}ycc}}w) z Set properties of the `.Text` labels. .. versionadded:: 3.7 Parameters ---------- props : dict Dictionary of `.Collection` properties to be used for the radio buttons. rnrrrrrrzN)rrrrrrrrr:rrr;rmrrrr8)rrorr<s rset_radio_propszRadioButtons.set_radio_propss d%0 %<__UYYs^S=MNE'N U#"mm99; t"" #q ("$))D,?,?,/ ,<1#FD  ##&)$++t7J7J&K M"{!MMOt/B/BB[ N M N Ms+E c|jSr)r6rs rr<zRadioButtons.activecolors   r!cdtj|||_|jd|iy)N)r<r)r _check_color_liker6rA)rr<s rr<zRadioButtons.activecolors+  [9' k;78r!c|tt|jvrtd||j|j |_||_|jj}tjd|ddtj|j|||<|jj||jr|jr|j%|j j#|j|j$j'|j|j j)|j$j*n|j j-|j.r8|j0j3d|j|j yy)a9 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. zInvalid RadioButton index: rzNrm)rrrr%rr8r9r:rr rr;rrCrxrrOrrIrrrrrDrzr)rrbutton_facecolorss rr;zRadioButtons.set_activesL c$++./ /:5'BC C"kk%099;# MM779%~~f5!#)>>$2E2Ee2L#M%  ##$56 ;;}}##/KK..t/?/?@##DMM2   .   " == OO # #It{{5/A/J/J/L M r!c:|j|jy)z4Reset the active button to the initially active one.N)r;r7rs rrzRadioButtons.clears ,,-r!c:|jjd|S)rrmrrs rrzRadioButtons.on_clickeds&&&y$77r!c:|jj|yrrrs rrzRadioButtons.disconnect rr!)rN)r0r1r2r3r rrrrArEr<setterr;rrrrrs@rr1r1sx,iF4TiFV+ S"N0!!99 #NJ.8*(r!r1c"eZdZdZdZdZdZy) SubplotToolz= A tool to adjust the subplot params of a `.Figure`. c t||_||_|jdd|jdg|_gd}t ||j t|dzD]p\}}|jdt||ddt|j| }|j|j|jj|r|jd j!|j\|_|_|_|_|_|_|j"|j$|j*|j,fD] }d|_ |j&|j(fD] }d|_ |j&|j"_|j"|j&_|j(|j$_|j$|j(_|j7gd }t9|d |_|j:j=|j>y )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?)rrz'Click on slider to adjust subplot param)rrrrwspacehspacerFr)rrw)g?rr|g333333?ResetN) figure targetfigsubplots_adjustsuptitle_slidersrsubplotsrr~rr subplotparsr$_on_slider_changedrSaxesremove sliderleft sliderbottom sliderright slidertop sliderwspace sliderhspacerrrradd_axesrf buttonresetr _on_reset)rrStoolfignamesrrIsliderbaxs rr zSubplotTool.__init__s "S4BC FE7#3#3CJN#CD )HD" OOE "Ba$+I,A,A4$HJF   d55 6 MM  (  )  R!15 /$+T-=t~ D-(9(9(($*;*;= %F$F  %''8 %F$F  %%)$4$4!%)__"&*nn##'#4#4 78!#w/ ##DNN3r!c |jjdi|jDcic]'}|jj |j )c}|j r%|jjjyycc}wrh) rSrTrVrvrrrCrOr)rrrgs rrYzSubplotTool._on_slider_changed@st&&& -!]],||$$& 2, - ;; NN ! ! & & ( ,s,B c t5}|jtj|d|jD])}|jtj|dd+|jD]}|j  ddd|j r|jj|jdy#1swYAxYw)NF)rC)rCrD) rrr _setattr_cmrVrrCrOrrY)rrArrgs rrdzSubplotTool._on_resetGs [ E    1 1$u E F-- M##%%fUUKM M--     ;; LL    %  s BC  CN)r0r1r2r3r rYrdr4r!rrLrLs)4V)&r!rLc8eZdZdZddddfd ZdZdZxZS)Cursora+ 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)horizOnvertOnrgc t|||jd|j|jd|jd|_||_||_|xr|jj|_ |jrd|d<|j|jdfddi||_ |j|jdfddi||_d|_d|_y)NrrrTr~rrF)rsr rVonmoverrrnrorOrwrgr get_yboundlinehr get_xboundlinev background needclear)rrIrnrorg linepropsrs rr zCursor.__init__ts  0$++> <4   <4;;#<#< <<$(Ij !RZZ  2OEOYO RZZ  2OEOYO r!c|j|s|jjry|jr5|jj |j j |_yy)z+Internal event handler to clear the cursor.N)rBrOrrgrrIrrvr@s rrz Cursor.clearsJ ;;u !6!6!8  <<"kk88FDO r!c|j|ry|jjj|sy|jj |dsd|j jd|jjd|jr!|jjd|_ yd|_ |j|\}}|j j||f|j j|jxr |j|jj||f|jj|jxr |j |jr|js |j sy|j"r|j$%|jj'|j$|jj)|j |jj)|j|jj+|jj,y|jj/y)z?Internal event handler to draw the cursor when the mouse moves.NrFT)rBrO widgetlockr$rIrrurrsrwrrdrrrorrnrgrvrrrrrrrAr]r^s rrqz Cursor.onmoves ;;u  {{%%//5 ww&q) JJ " "5 ) JJ " "5 )~~   "!& ,,U3 u eU^, t||; < eU^, t||< = $++  <<* **4??; GG   + GG   + KK  TWW\\ * KK ! ! #r!)r0r1r2r3r rrqrrs@rrmrmXs!6'+4(G$r!rmc8eZdZdZdddddZdZdZdZd Zy ) MultiCursora 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)rgrnroc r||_||_||_||_|Dcic]"}|j dj gdd$c}|_|dj\}} |dj\} } d|| zz} d| | zz} d|_ |xrtd|j D|_ |jrd|d<|Dcgc]}|j| fdd i|c}|_ |Dcgc]}|j| fdd i|c}|_|j!ycc}wcc}wcc}w) NTrL)cidsrvrwric34K|]}|jywr)rw).0rOs r z'MultiCursor.__init__..sJVF((Jsr~rF)_canvasrZrnrorNrO _canvas_infosget_xlimget_ylimrallrgrrrhlinesr)rrOrZrgrnrorxrIxminxmaxyminymaxxmidymids rr zMultiCursor.__init__sc    <@A57 MMtM $ + +40 1A"X&&( d"X&&( ddTk"dTk"  KJt7I7IJJ  <<$(Ij !"&'"rzz$CCC' "&'"rzz$CCC'  -A"''s'D* D/5D4c|jjD]@\}}|jd|j|jd|jg|d<By)zConnect events.rrrrN)rrrRrqr)rrOinfos rrzMultiCursor.connectsX ..446 LFD""#8$++F""<<DL r!c|jjD]3\}}|dD]}|j||dj5y)zDisconnect events.rN)rrrXr)rrOrrUs rrzMultiCursor.disconnectsU ..446 !LFDF| +%%c* + L    !r!c|j|ry|jrd|jjD]F\}}||jj ur|j |jj|d<Hyy)zClear the cursor.Nrv)rBrgrrrRrOrr)rrArOrs rrzMultiCursor.clearsw ;;u   << $ 2 2 8 8 : O  !5!55%+%:%:6==;M;M%N\" O r!c~|jDcgc]}|j|ds|}}|j|s'|r%|jjj |syt j|}|j|ur|j|jfn>|jjj|j|jf\}}|j D]>}|j#||f|j%|j&xr |j(@|j*D]>}|j-||f|j%|j&xr |j.@|j&r|j(s |j.sy|j0r|j2j5D]\}}|ds |j7|d!|j(r9t9|j|j D]\}}|j;||j.r9t9|j|j*D]\}}|j;||j2D]}|j=y|j2D]}|j?ycc}w)Nrrv) rZrrBrOr{r$r _topmost_artistr\r]r^r_r`rarbrcrrrrrorrrnrgrrrrrrr) rrArIaxsr]r^linerOrs rrqzMultiCursor.onmoves; II?bU);A)>r?? ;;u S 0G0G0Q0QRV0W   " "3 '6;llb6Hekk2\\224>>?QR uKK ;D NNE5> *   T\\9dkk : ;KK *   T\\:dll ; < $++  << $ 2 2 8 8 : >  %))$|*<= >{{ #DIIt{{ ;)HBNN4()|| #DIIt{{ ;)HBNN4(),,   ,, #  " #9@s J:J:N) r0r1r2r3r rrrrqr4r!rr~r~s,"H15eD D! O#r!r~ceZdZ d fd ZfdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZedZdZdZdZ dZ!dZ"xZ#S)!_SelectorWidgetct||d|_| d|_n||_|xr|jj |_|jtddddd|_ |jj|xsi||_ d|_ t|tr |g|_n||_d |_d|_d|_d|_t)|_y) NTcyrr4)argss rrPz*_SelectorWidget.__init__..<r! escapeshiftcontrolr)moversquarerjrotateF)rsr _visibleonselectrOrwrgconnect_default_eventsr_state_modifier_keysr_use_data_coordinatesrvrr validButtons_selection_completed _eventpress _eventrelease _prev_eventr_state)rrIrrgrstate_modifier_keysuse_data_coordinatesrs rr z_SelectorWidget.__init__6s   .DM$DM<4;;#<#<  ##%$(c07 03%5! !!(()<)BC%9" fh '!'D  &D %*! !e r!cLt|||r|jdyyr)rsr;update_background)rr:rs rr;z_SelectorWidget.set_activeYs& 6"   " "4 ( r!cxtfdjjjDS)aG 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. c3K|]9}|jD]$}|jr|jvr|&;ywr) get_children get_animatedartists)rax_ars rrz8_SelectorWidget._get_animated_artists..fsLD3!..0D(Qdll-BDQDs?A)tuplerIrNget_axesrs`r_get_animated_artistsz%_SelectorWidget._get_animated_artists^s8D$''"4"4"6"?"?"ADD Dr!cB|jsy|jjryt|j|j zd}t d|D}t5}|rB|D]#}|j|jd%|jj|jj|jj|_ddd|r#|D]}|jj|yy#1swY/xYw)z"Force an update of the background.Nc"|jSr get_zorderrs rrPz3_SelectorWidget.update_background..zs q||~r!rc3<K|]}|jywr) get_visible)rartists rrz4_SelectorWidget.update_background..{sFF6--/FsF)r)rgrOrsortedrrrrr_cm_setrrrIrrvr)rrAr needs_redrawrrs rrz!_SelectorWidget.update_backgroundjs||  ;; " (B(B(DD57FgFF [ GE%GF''u(EFG   ""kk88FDO  G ! ,##F+ ,   G Gs .A9DDc|jd|j|jd|j|jd|j|jd|j|jd|j |jd|j |jd|jy) z+Connect the major canvas events to methods.rrrprqrrkey_release_event scroll_eventN)rVrqpressr*r on_key_presson_key_release on_scrollrs rrz&_SelectorWidget.connect_default_eventss 0$++> /< 14<<@ <)?)?@ ,d.?.?@ .0C0CD >4>>:r!c2|jr|jjsy|jjj |syt |dsd|_|j|j|jvry|j|jj|d S|j|jjk(ry|jj|d xs#|j|jjk7S)NTrrF) r:rIrrOr{r$rrrrrr@s rrBz_SelectorWidget.ignores{{$''"5"5"7{{%%//5uh'EL    )LL(9(99    #ww''.q11 1 <<4++22 2GG$$U+A..8  0 0 7 77 9r!cV|jjr*|jjdjy|jr|j &|j j|j n|jdt|j|jzd}|D]}|jj||j j|jjy|j jy)z@Draw using blit() or draw_idle(), depending on ``self.useblit``.TrLNc"|jSrrrs rrPz(_SelectorWidget.update..s 1<<>r!r)rIrrNrrgrvrOrrrrrrrrr)rrrs rrz_SelectorWidget.updates##%"""-;;=E  <<* **4??;&&t,T\\D,F,F,HH!9;G! ,##F+ , KK  TWW\\ * KK ! ! #r!c|jy|j|\}}tj|g|jj }tj|g|jj }||fS)z/Get the xdata and ydata for event, with limits.)NN)r]rdrcliprIrtrrr|s r _get_dataz_SelectorWidget._get_datasm ;; ,,U3 u5 2 2 455 2 2 45e|r!c|j |j}ntj|}|j|\|_|_||_|S)a 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. )r]rcopyrr^r@s r _clean_eventz_SelectorWidget._clean_eventsK ;; $$EIIe$E#'>>%#8  U[  r!c&|j|s|j|}||_||_|jxsd}|j dd}||j dk(r|jjd|j|yy)z#Button press handler and validator.r/ctrlrrTF) rBrrrrreplacerradd_press)rrArs rrz_SelectorWidget.presss{{5!%%e,E$D $D ))/rC++fi0Cd//77 ' KK r!cy)Button press event handler.Nr4r@s rrz_SelectorWidget._pressrr!c|j|s_|jrS|j|}||_|j |d|_d|_|j j dyy)z+Button release event handler and validator.NrTF)rBrrrr|rdiscardr@s rr*z_SelectorWidget.releasesb{{5!d&6&6%%e,E!&D  MM% #D !%D  KK   'r!cy)Button release event handler.Nr4r@s rr|z_SelectorWidget._releaserr!c|j|s/|jr#|j|}|j|yy)(Cursor move event handler and validator.TF)rBrr_onmover@s rrqz_SelectorWidget.onmoves8{{5!d&6&6%%e,E LL r!cy)Cursor move event handler.Nr4r@s rrz_SelectorWidget._onmove rr!cJ|j|s|j|yy)z)Mouse scroll event handler and validator.N)rB _on_scrollr@s rrz_SelectorWidget.on_scroll s{{5! OOE ""r!cy)zMouse scroll event handler.Nr4r@s rrz_SelectorWidget._on_scroll rr!c|jr|jxsd}|jdd}||jdk(r|j y|jj D]\}}||j dvs|dk(rF||jvr|jj|I|jj|e|jj||j|yy)z@Key press event handler and validator for all selection widgets.r/rrrN+r) r:rrrrrsplitrrr _on_key_pressrrArrmodifiers rrz_SelectorWidget.on_key_press s ;;))/rC++fi0Cd//88 %)%>%>%D%D%F /!syy~-( DKK/ KK//6 KKOOE2 . /   u %# r!cy)z@Key press event handler - for widget-specific key press actions.Nr4r@s rrz_SelectorWidget._on_key_press rr!c|jry|jxsd}|jjD]:\}}||j dvs|dk7s |j j |<|j|yy)z(Key release event handler and validator.r/rrN)r:rrrrrr_on_key_releasers rrz_SelectorWidget.on_key_release# sy ;;))/rC%)%>%>%D%D%F /!syy~-%82CKK''.  /   ' r!cy)Key release event handler.Nr4r@s rrz_SelectorWidget._on_key_release. rr!cV||_|jD]}|j|y)z+Set the visibility of the selector artists.N)rrr)rrrs rrz_SelectorWidget.set_visible1 s* ll (F   w ' (r!c|jS)z+Get the visibility of the selector artists.)rrs rrz_SelectorWidget.get_visible7 s }}r!cD|j|jy)zAClear the selection and set the selector ready to make a new one.N)_clear_without_updaterrs rrz_SelectorWidget.clear; s ""$ r!c4d|_|jdyNF)rrrs rrz%_SelectorWidget._clear_without_update@ s$)! r!c<t|dd}|jf|zS)z%Tuple of the artists of the selector._handles_artistsr4)r_selection_artist)rhandles_artistss rrz_SelectorWidget.artistsD s'"$(:B?&&(?::r!c |j}tj||}|jdi||jr|j yy)z Set the properties of the selector artist. See the *props* argument in the selector docstring to know which properties are supported. Nr4)rr rirrgr)rrors r set_propsz_SelectorWidget.set_propsJ sG''&&uf5 U << KKM r!c 0t|ds td|jd}tj||}|jD]}|j di||j r|j|jj|y)z Set the properties of the handles selector artist. See the `handle_props` argument in the selector docstring to know which properties are supported. rz#This selector doesn't have handles.rNr4) rNotImplementedErrorrr rirrgr _handle_props)r handle_propsrrYs rset_handle_propsz _SelectorWidget.set_handle_propsW s t/0%&KL L&&q)--lFC ++ 'F FJJ & & ' << KKM !!,/r!c|jjDcgc]\}}|dk7r|dk7r|}}}tj||ycc}}w)Nrnot-applicabler)rrrr)rrrvaluesupported_states r_validate_statez_SelectorWidget._validate_stateh sX"&";";"A"A"CCg~%+;";  ?%8 sAc\|j||jj|y)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 rrrrs r add_statez_SelectorWidget.add_stateo s"" U# r!c\|j||jj|y)a 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 rr[rs r remove_statez_SelectorWidget.remove_state s$" U# 5!r!)NFNNF)$r0r1r2r r;rrrrBrrrrrr*r|rqrrrrrrrrrrrrErrrr rrrrs@rrr4s@D@E!F) D,8;90$*" * ,)# *&*O ()(   ;; 0"9("r!rc eZdZdZddddddddddddd fd Zdddd Zd Zed Zd Z fd Z dZ edZ e jdZ dZdZdZdZdZdZedZedZejdZdZxZS) SpanSelectora 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` rFNr) minspanrgroonmove_callback interactiverr grab_rangerdrag_from_anywhereignore_event_outside snap_valuesc | tdddd} t| |||| | | tdd}|j|d<||_d|_||_||_||_| |_ ||_ d|_ | |_ ||_ |j||d d |jd d it!j"| t$|_|jr$ddg|_|j+|j&d|_y)Nrr )rrrjr)rgrrredri)ralphar~T_props_initrrrrFrJ)rrsr rg direction_extents_on_pressrrrr _interactive _edge_handlesrrnew_axesrr rirr _edge_order_setup_edge_handlesr8)rrIrr"rrgrorrrrrrrrrrs rr zSpanSelector.__init__ s&  &"&X.>.>.>#@  Xwv-@  B =54E LLj"!%&. $'!"4$8! bd 3 UYY{C0<$$\6:<    %u~D   $ $T%7%7 8"r!rc&d}|s(|j|jdjur|j|jd}||_|r|j d|_|j dk(r|j}d\}}n|j}d\}}td|||d }||j|n'|j|j|j|jj|||_ y) z*Set SpanSelector to operate on a new Axes.FTrLNrr)rrrr)rar)rOrNrZrIrrr"r0r/rrr update_fromr) rrIr r! reconnecttranswrW rect_artists rr&zSpanSelector.new_axes s DKKr}}$}'?'F'FF{{&&&(I   ' ' )%*! >>\ )**,EDAq**,EDAq1uM     v &  # # /  # #D$:$: ; +&!,r!c|jdk(r|jj}n|jj}t |j||j||j |_y)Nr)r" line_propsrg)r"rIrtrrToolLineHandlesrgr%)rro positionss rr(z SpanSelector._setup_edge_handles5 sY >>\ )**,I**,I,TWWi7;~~8=59\\Cr!cH|j|jjSyrh)r%rrs rrzSpanSelector._handles_artists@ s#    )%%-- -r!c.|rD|jdk(rtjjntjj}ntjj }|j jdjj|y)zzSpanSelector._hover se ;;u      *$2K2K &&..uww@ 6 4??23r!cL|j|\}}|jdk(r|}|jj}n|}|jj}|j dk(r+|j |j \}}||z }||z }||z }ne|j r3|j dk7r$|j \}}|j dk(r|}n)|}n&|jr |jry||}}||kDr||}}|j||f|j|j||y)zMotion notify event handler.rCNrFF) rdr"rr]r^r8r#rrrAr) rrAr]r^rvpressrArBdvs rrzSpanSelector._onmove s4,,U3 u >>\ )A%%++FA%%++F   # %$*@*@*L//JD$VB BJD BJD T%8%8C%?//JD$""e+ ((T-F-F$Dd{!4d 4,'    +  t ,r!c||kDr||}}|jdk(r:|jj||jj||z y|jj ||jj ||z y)Nr)r"rset_xrset_yrrrArBs r _draw_shapezSpanSelector._draw_shape sv $;t$D >>\ )  " " ( ( .  " " , ,TD[ 9  " " ( ( .  " " - -dTk :r!c|jj|j|j\}}d|jvrd|_nh||j kDrEd|_|jr*|j|rd|_|j|_ nd|_y|j||_|j|_ y);Set active handle based on the location of the mouse event.rrON) r%rLrbrcrr8rr _containsrIr#r')rrAe_idxrMs rr@zSpanSelector._set_active_handle s**22577EGGD v T[[ "%D  doo %"&D &&4>>%+@&)#)-&&*##'"2"25"9D "&r!cB|jj|ddSz)Return True if event is within the patch.r)radiusrrr@s rrYzSpanSelector._contains #%%..uQ.?BBr!ctjtjtjdzt fd|DS)z2Snap values to a given array values (snap_values).g-q=c3K|]F}tj|z tj|zzjHywr)rrsignr)rrepsrs rrz%SpanSelector._snap.. sF {Qc1AABIIK LsA A)rrFrdiffr)valuesrrcs `@r_snapzSpanSelector._snap sDffRVVBGGK012U: r!c |jdk(r;|jj}||jjz}||fS|jj }||jj z}||fS)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"rr get_widthr get_heightrUs rrIzSpanSelector.extents s >>\ )))//1D$00::<rrVr@rY staticmethodrfrIrArrs@rrr sPd<=eTu4B%)e&+ +#Z&*-: C @C : ( (> 4*X;.4C   ^^)) r!rcleZdZdZddddZedZedZedZd Z d Z d Z d Z d Z y)r2a` 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)r1rgc||_tjddg|||_i||nid|d}|jdk(r |j n |j }|Dcgc] }||fi| c}|_ycc}w)NrrrGF)rr~)rIrrrDr"rr_artists)rrIr3r"r1rgline_funps rr zToolLineHandles.__init__J s L*5K# '3z  "&K7;||Dt%f%'*DDDsAc|jS)z4Direction of the handle: 'vertical' or 'horizontal'.rCrs rr"zToolLineHandles.directione rEr!c|jdk(rdnd}t|j|D]\}}t||||gy)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 rrrN)r"rrr)rr3rwrrts rrnzToolLineHandles.set_dataj sI!%, >K4<<3 *GD! !GD& !1a& ) *r!cH|jD]}|j|y)z/Set the visibility state of the handles artist.N)rrrr rs rrzToolLineHandles.set_visiblex s#ll &F   u % &r!cH|jD]}|j|y)z-Set the animated state of the handles artist.N)r set_animatedr{s rr}zToolLineHandles.set_animated} s#ll 'F    & 'r!cF|jD]}|jy)z*Remove the handles artist from the figure.N)rrr[)rrs rr[zToolLineHandles.remove smm F MMO r!c |jdk(rdtj|jDcgc],}|jj j |dfd.c}}t||z }nctj|jDcgc],}|jj j d|fd.c}}t||z }tj|}|||fScc}wcc}w)ar 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 rrr) r"rr.r3rIr_rarr)rrbrcrtp_ptsdistrs rrLzToolLineHandles.closest s >>\ )HH@D;<!!++QF3A6Euqy>DHH@D;<!!++QF3A6Euqy>D $d5k!! s 1C31C8)r0r1r2r3r rErr3r"rnrr}r[rLr4r!rr2r26 sn&@DG"$$EE  *& '  "r!r2cjeZdZdZdddddZedZedZed Zdd Z d Z d Z d Z y) ToolHandlesaO 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'NTrr rgc||_|dddddddtj|tj}t||fd|i||_|jj |j y) Nr.rzriF _nolegend_)r markersizemarkerfacecolor linestylerrrvr~)rIr rir _alias_map_markersadd_line)rrIrbrcrr rgros rr zToolHandles.__init__ sp!s$su&L)),8I8IJLq!?g??  'r!c6|jjSr)rrUrs rrbz ToolHandles.x }}&&((r!c6|jjSr)rrVrs rrcz ToolHandles.y rr!c|jfSr)rrs rrzToolHandles.artists s   r!cp||}tj||g}|jj|y)z!Set x and y positions of handles.N)rr.rrn)rptsrcrbs rrnzToolHandles.set_data s0 =A((Aq6"C s#r!c:|jj|yr)rrr s rrzToolHandles.set_visible s !!#&r!c:|jj|yr)rr}r s rr}zToolHandles.set_animated s ""3'r!c tj|j|jg}|jj j |}|||gz }tj|j}tj|}|||fS)z1Return index and pixel distance to closest index.) r column_stackrbrcrIr_rahypotTr)rrbrcrrdr min_indexs rrLzToolHandles.closest srootvvtvv./gg))#.aV|xx IIdO $y/))r!r) r0r1r2r3r rErbrcrrnrr}rLr4r!rrr se&,/T4())))!!$'(*r!ru 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@eZdZdZddddddddddddddd fd Zed Zd Zd Zd Z d Z edZ dZ dZ edZedZedZedZej$dZedZej$dZdZdZdZedZxZS)RectangleSelectora 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` NrFdatar) minspanxminspanyrgro spancoordsrrrrrrrrc Zt|||||| || |_| |_||_d|_d|_d|_|tdddd}i|d |ji}|jd |j|_ |jdi|}|jj|||_|j!||_||_t'j(d d g| ||_| |_|jrd|xsij/ddit1j2| t4|_gd|_|j:\}}t=|j|||j6|j|_gd|_ |jB\}}t=|j||d|j6|j|_"|jF\}}t=|j|g|gd|j6|j|_$d|_%d|_&y)N)rgrrrgg?Trr{rN)rrrfillr~rrpixelsrmarkeredgecolorr)SWSENENW)r rg)WSENrrr4)'rsr r$rr _rotation_aspect_ratio_correction_allow_creationrrgrr _init_shaperIrr_set_aspect_ratio_correctionrrrrrrrr rirr _corner_ordercornersr_corner_handlesr' edge_centersr%rj_center_handler8r#)rrIrrrrgrorrrrrrrrrto_drawxcycxeyers rr zRectangleSelector.__init__] s Xwv-@.B  D("4$8!(+% $ =5G"/E353*dll3 )T]]; "$""+U+ '"!( ))+     FH-*E$$   !EKR#4#4['#J"@((v>"@D ":D \\FB#.twwB<@:L:L59\\"CD [[FB"-dggtbT#;?;M;M6:ll#DD #'D !%r!cg|jj|jj|jjSr)rrrr%rs rrz"RectangleSelector._handles_artists sF-$$,,-t/C/C/K/K-##++- -r!c tdddd|S)Nr*rrFrj)rrotation_point)rrs rrzRectangleSelector._init_shape s!;u(0;49; ;r!c|jr,|jjr|j|nd|_|j |js|j r|j |jF|js:|j r.|j|\}}d|_ ||||f|_ d|_ n|jd|j|_ |j|_|jy)rNFT)r$rrr@r8rrrrdrrIrr#r_rotation_on_pressr)rrArbrcs rrzRectangleSelector._press s   !7!7!C!C!E  # #E *"&D   (0A0A$$ KKM    '0I0I$$((/DAq!DMaA:DL DM   T "!%"&.. ))+r!c|js|jjd|j|jr |j ry|j \}}}}||j_||j_ |jjj||g}|\|j_ |j_||j_||j_ |jjj||g}|\|j_ |j_|j dk(rmt#|jj|jjz }t#|jj|jjz } n|j dk(rmt#|jj|jjz }t#|jj|jjz } n#t%j&ddg|j |j(ks |j*krC|jr&|j-|j|j|j/n-|j-|j|jd|_|j1d|_d|_y)rFNrrrT)r$rrr8rrrIrr]r^rIr_rarbrcrrrrrrrrrrr#) rrArrrrxy0xy1spanxspanys rr|zRectangleSelector._release sV   " " . .u 5    'D,E,E)) BB!#!#gg))2r(314.D,,.#% #% gg))2r(3582d002 ??f $((..1C1C1I1IIJE((..1C1C1I1IIJE __ (((**T-?-?-A-AABE((**T-?-?-A-AABE   1*.// ; DMM !Udmm%;(( d..0B0BC  & & ( MM$**D,>,> ?(,D % "!%r!c< |j}|j}d|vxr|j|jv}|jdk(}|jxr| }|j |\}}|rh|j j } | j||g\}}| j|j|jf\|_|_ ||jz } ||jz } d} |jr| | }} n2|j|jz } |j|jz }|j\}}}}|r|j|jf}|j}||f}tj |d|dz |d|dz tj |d|dz |d|dz z }tj"|j$|z|_n|r=||z ||z g}||ddz z||ddz zf}d|vrd|vrm|j|jvrt)| |t* } |jd vs| | k(r||dz }||j,z }n||dz }||j,z}nl|ddz }|ddz }|jd d g|jzvrt+||dz }|jd dg|jzvrt+||dz }|d|z |d|z|d|z |d|zf\}}}}n{d |jvr|}d|jvr|}|jd d g|jzvr|}|jd dg|jzvr|}d|vr|j|jvrt)| |t* } |jd vs| | k(r;tj.||z }||t+||z z|j,z z}ntj.||z }||t+||z z|j,zz}ne|rE|j\}}}}||jz } ||jz } || z }|| z }|| z }|| z }nd|_|j2r |j4s |j6sy|j|jg}||dz dz } ||dz dz } d|vrtt)| |t* } | | k(r/tj.| t+| z|j,z } n.tj.| t+| z|j,z} d|vr | dz} | dz} n|dxx| z cc<|dxx| z cc<|d| z |d| z|d| z |d| zf\}}}}||||f|_y)z Motion notify event handler. This can do one of four things: - Translate - Rotate - Re-size - Continue the creation of a new shape rrONrrr)rjrr)rrrrrr)rrr8rrd_get_rotation_transformr`rar]r^rrbrcr#rjrarctan2rad2degrrotationrJrrrbrrrrrI)rrA eventpressrrrresizer]r^inv_trdxdyrefmaxrefxrefyrrrrrbrYangle size_on_pressrjhwhhrbs rrzRectangleSelector._onmove s %%  U"Pt':':d>P>P'P""c)$$1T,,U3 u 113<<>F!++UEN;LE5171A1A!!:#3#3426 .J j.Z%% % Z%% %  % %R$D77Z\\)D77Z\\)D//BB !!:#3#34A AAZZ!QqT 1Q4!95ZZ!QqT 1Q4!956EJJt'>'>'FGDM "Wb2g.M=+a//mA6F6J1JKF5 u$**d.@.@@!$T4S!9**j8FdN"VAY.$"?"??"VAY.$"?"??&q)A-B&q)A-B**sCj4;M;M.MM !23**sCj4;M;M.MM !23"()b.&)b."()b.&)b."BBB $---B$---B&&3*t7I7I*IIB&&3*t7I7I*IIBu$**d.@.@@!$T4S!9**j8FdN!wwurz2$R"W"58U8U"UU!wwurz2$R"W"58U8U"UU !33NBB)))B)))B "HB "HB "HB "HBDN**t/H/H,, && (8(89F&)#q(B&)#q(B5 T4S1T>s2w.1N1NNBs2w.1N1NNB5 aaq R q R $Qi"nfQi"n$Qi"nfQi"n>NBB2r2~ r!cJ|jjjSr)rget_bboxboundsrs r _rect_bboxzRectangleSelector._rect_bbox s%%..0777r!c|jj}||j_|jrd|_y||_y)Nr)rI_get_aspect_ratiorrrr aspect_ratios rrz.RectangleSelector._set_aspect_ratio_correction s;ww002 :F7  % %,-D ),8D )r!cH|jj}tj|jd |jd j d|j |jj dd|z j|jSNrr)rIrr translaterjscalerrrs rrz)RectangleSelector._get_rotation_transform s~ww002 xz##T[[^Odkk!n_Eq,''q!l*+DKK ) )r!c|j\}}}}|||z||z|f}||||z||zf}|j}|jtj||gj j }|d|dfS)ze Corners of rectangle in data coordinates from lower left, moving clockwise. rrrrrarr.r) rrrrrrrrars rrzRectangleSelector.corners s !%Bv eR%Z + R&["v+ -002 $$RXXr2h%7%9%9:<<ay&)##r!c|j\}}}}|dz }|dz }|||z||z||zf}||z|||z||zf}|j} | jtj||gj j } | d| dfS)zk Midpoint of rectangle edges in data coordinates from left, moving anti-clockwise. @rrr) rrrrrr.rWrrrars rrzRectangleSelector.edge_centers s !%Bv BJ RK aeR!V + !VRaf ,002 $$RXXr2h%7%9%9:<<ay&)##r!cD|j\}}}}||dz z||dz zfS)z(Center of rectangle in data coordinates.r)r)rrrrrs rrjzRectangleSelector.center s2!%BvEBJVb[ 000r!c||j\}}}}t|||zg\}}t|||zg\}}||||fS)z} Return (xmin, xmax, ymin, ymax) in data coordinates as defined by the bounding box before rotation. )rr) rrrrrrrrrs rrIzRectangleSelector.extents sS !%BvRe,- dRf-. dT4%%r!cz|j||jrs|jj|j|j j|j |j\}}|jj|g|g|j|j|jyr) rVr$rrnrr%rrjrrrr)rrIrbrcs rrIzRectangleSelector.extents s !    )D ) )4<< 8 'D   ' '):): ;;;DAq    ( (!qc 2 ' r!c@tj|jS)u Rotation in degree in interval [-45°, 45°]. The rotation is limited in range to keep the implementation simple. )rrrrs rrzRectangleSelector.rotation s zz$..))r!crd|kr2|dkr,tj||_|j|_yyy)Ni-)rdeg2radrrI)rr s rrzRectangleSelector.rotation s3 %>%+@&)#&*# f_"&"4"4U";D #'"2"25"9D r!cB|jj|ddSr\r^r@s rrYzRectangleSelector._containsr_r!cjt|jdrq|jjj }|j |jj j\}}tj||gStj|jjS)a 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) rrrIr_r`rarrrr.get_data)rxfmrcrbs rgeometryzRectangleSelector.geometrys 4)); 7''##,,.C==!7!7!A!A!CDFFDAq88QF# #88D22;;=> >r!r)r0r1r2r3r rErrrr|rrrrrrrjrIrJrrVr@rYrrrs@rrr= s5:@&aUt"%)e&+% @&D--;8.`M&^889) $ $ $ $11 && ^^  **__((8$:8C ? ?r!rellipsec,eZdZdZdZdZedZy)EllipseSelectorao 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 tdddi|S)NrrF)rrs rrzEllipseSelector._init_shape6s>r!rc@eZdZdZd ddddfd ZdZdZdZxZS) LassoSelectora 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)rgrorct|||||d|_i||ni|jdd}t ggfi|}|j j |||_y)N)rgrF)r~r)rsr rCrgrrIrr)rrIrrgrorrrs rr zLassoSelector.__init__wss XwvF  )ur     b"&& !%r!ch|j|g|_|jjdyrk)rrCrrr@s rrzLassoSelector._presss)nnU+,  **40r!c$|jE|jj|j||j|j|jj ggg|jj dd|_yr)rCrSrrrrnrr@s rr|zLassoSelector._releasesj :: ! JJ  dnnU3 4 MM$** % ''R1 **51 r!c|jy|jj|j||jj t t |j|jyr)rCrSrrrnlistrrr@s rrzLassoSelector._onmovesU ::   $../0 ''S$**-=(>? r!r) r0r1r2r3r rr|rrrs@rrrNs(&P &Td &1r!rc eZdZdZdddddddddfd ZdZdZd Zd Zd Z e d Z d Z dZ dZdZdZdZdZdZdZe dZej,dZdZxZS)PolygonSelectora 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)rgrorrdraw_bounding_boxbox_handle_props box_propsc ftddddddd} t | |||| dg|_|tdd d d }i|d |ji}t ggfi|x|_} |jj| |td|jdd}||_ t|jgg|j|j|_ d|_ ||_|jd||_d|_|i}|jj%||_| |_y)Nrrrr )r move_vertexmove_allrrrjr)rgrr*r-r)ri)rrryrr~r)rr)rgr rwT)rrsr _xysrgrrrIrrrr_polygon_handles_active_handle_idxrr _draw_box_boxr_box_handle_props _box_props) rrIrrgrorrrrrrrrs rr zPolygonSelector.__init__sL#y,3:J*:*:*: < Xw-@  BH =scQcJE353*dll3(.r2(?(??   05 '30GIL) +DGGR48LL9=9K9K!M#%$ *  #! !%!3!3!:!:;K!L#r!c6|jjSr)rrrs r _get_bboxzPolygonSelector._get_bboxs%%..00r!ct|j|j|j|j|j d|_|j jjd|j jd|j|jd|j _ d|j _ |jy)NT)rgrrrorrrrF)rrIrgrrrrrrrV_scale_polygon _update_boxrr _draw_polygonrs r_add_boxzPolygonSelector._add_boxs%dgg.2ll15373I3I,0OO26 8 &&**84  5t7J7JK %* !)- & r!cb|j#|jjdd|_yyr)rrrs r _remove_boxzPolygonSelector._remove_box%s* 99 II ! !% (DI !r!c|ji|j}|j|j|j|j g|j_|jj |_yyr)rrrrrrrI_old_box_extents)rrs rr!zPolygonSelector._update_box*sT 99 >>#D!%$''477DGG DDII $(II$5$5D ! !r!c|jsy|j|jjk(ry|jj\}}}}|j }t jj|j |j jd|jz d|jz j||j||}|jtj |j"D cgc] \}} || f } }} g| | d|_|j'|jj|_ycc} }w)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. Nrr)rr'rrIrrrrrrrrrrrarr.rCrr") rrArrw1h1old_bboxtrbrc new_vertss rr zPolygonSelector._scale_polygon2s((   DII$5$5 5 --BB>>#  "i x{{l3eA&HOO(;<eBmiB )* BHHTZZ4H(IJ1aVJ J.i.1.   $ 1 1KsEc.|jjSr)rrrs rrz PolygonSelector._handles_artistsNs$$,,,r!ct|jdkDr|jr{|dt|jdz fvr_|jjd|jjd|jj |jdn|jj|t|jdkrd|_|j yy)zRemove vertex with index i.r)rrrwFN)rrrrrSr%)rrs r_remove_vertexzPolygonSelector._remove_vertexRs  NQ ))aTYY!+,, IIMM!  IIMM"  II  TYYq\ * IIMM!  tyy>Q ).D %     r!c8|jsd|jvrat|jdkDrI|jj |j |j\}}||jkr||_ |jj|_ y)rrrN) rrrrrrLrbrcrrr _xys_at_press)rrAh_idxh_dists rrzPolygonSelector._pressfsu & &-4;;*F NQ& 1199%''577KME6'*/'"YY^^-r!cj|jdk\rB|jdk(r+|j|j|jd|_nt |j dkDrO|j d|j dk(r0d|_|jrp|jd|jnS|j sGd|jvr9d|jvr+|j jd|j||j r|j|jyy)rrr?rwTNrr)rrr0r"rrrrrr#rinsertrdrrCr@s rr|zPolygonSelector._releasers  " "a '||q ##D$;$;<""$&(D #^a DIIbMTYYq\$A(,D %~~$))"3 ++DKK/t{{2 II  R!6!6u!= >  $ $ MM$** % %r!cH|j|ro|jjj|sI|jr=t j t j f|jd<|jy|j|}|j|y)rrwFT) rBrOr{r$rrnanr"rrr@s rrqzPolygonSelector.onmovesx ;;u ;;))33D9dii!# 0 " ""$%%e,E LL r!c>|jdk\r]|j}|j||j|<|dk(r|jr|j||jd<nd|jvr|j r|j|\}}||j j z }||j jz }tt|jD]+}|j|\}} ||z| |zf|j|<-n|jsd|jvsd|jvry|jjj|jd\} } tj| |j z | |j"z } t|jdkDr,| |j$kr|jd|jd<n|j||jd<|j'y)rrrwrrNr?)rrdrrrrr]r^rrr2r get_transformrarrrbrcrr") rrArRr]r^rrr x_at_press y_at_pressrrv0_dists rrzPolygonSelector._onmoves  " "a '))C!2259DIIcNaxD55 $ 5 5e < " 4;; &4+;+;007LE5))///B))///B3tyy>* @)-););A)>& J)B R? !  @ ''$++-t{{1J  &&446@@1N BhhrEGG|R%''\:G499~!g&? $ !  " $ 5 5e < "  r!c|jsHd|jvsd|jvr+|jj|j yyy)zKey press event handler.rrN)rrrrr"r@s rrzPolygonSelector._on_key_presssH))"dkk14;;. IIMMO    /*r!c$|js|j|jjdk(s(|j|jjdk(r;|jj |j ||jy|j|jjdk(rQ|j|}|j |g|_d|_|j|jdyy)rrrrFTN) rrrrrrSrdr"rr%rr@s rrzPolygonSelector._on_key_releases))d77;;MJJII!:!:!>!>z!JJ II  T2259 :    YY$3377@ @%%e,E..u56DI(-D %       T " Ar!c|jrt|jnggf\}}|jj|||j |j s7t |jdkDrB|jd|jdk(r#|jj|dd|ddy|jj||y)z>Redraw the polygon based on new vertex positions, no update().r?rwrN)rrrrnr!rrr)rxsrs r_draw_polygon_without_updatez,PolygonSelector._draw_polygon_without_updates$(IIdiiB8B ''B/   % % NQ& " 15  ! ! * *2cr7BsG <  ! ! * *2r 2r!cD|j|jy)z5Redraw the polygon based on the new vertex positions.N)rBrrs rr"zPolygonSelector._draw_polygons ))+ r!c |jddS)z4The polygon vertices, as a list of ``(x, y)`` pairs.Nrw)rrs rrCzPolygonSelector.vertssyy"~r!cg||d|_d|_|jd|jr|j|j |j y)z Set the polygon vertices. This will remove any preexisting vertices, creating a complete polygon with the new vertices. rTN)rrrrrr#r")rxyss rrCzPolygonSelector.vertssR#cN3q6N $(!  >>dii/ MMO r!cBd|_dg|_|jy)NFr*)rrrBrs rrz%PolygonSelector._clear_without_updates$)!H  ))+r!r)r0r1r2r3r rr#r%r!r rErr0rr|rqrrrrBr"rCrJrrrs@rrrsIV+$U$2#(4+$Z1  628--( .&0$%N!#$ 3  \\  ,r!rc6eZdZdZdddfd ZdZdZxZS)Lassoa 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)rgroc"t |||xr|jj|_|jr4|jj |j j|_dddd}||j||\}}||fg|_ t|g|gfi||_ |j j|j||_|jd|j |jd|j"y)Nrr{r))rrrrqrr)rsr rOrwrgrrIrrvrrCrrrrTrV onreleaserq) rrIr@rTrgrostylerbrcrs rr zLasso.__init__,s <4;;#<#< <<"kk88FDO!G1=   LL 1!fX A3-u-  #   14>>B 0$++>r!c\|j|ry|jw|jj|j|t |jdkDr|j |j|j jd|_|jy)Nr)) rBrCrSrdrrTrr[rZr@s rrKzLasso.onrelease@s{ ;;u   :: ! JJ  d33E: ;4::" djj) II      r!c|j|s9|j-|jdk7s|jj |dsy|jj |j ||jjtt|j|jrz|jj|j|jj|j|jj!|jj"y|jj%y)Nrr)rBrCrrIrrSrdrrnr rrgrOrrvrrrrr@s rrqz Lasso.onmoveKs KK ::%<<1$ww''.q1  $//67 4TZZ 012 << KK & &t 7 GG   * KK  TWW\\ * KK ! ! #r!)r0r1r2r3r rKrqrrs@rrIrI s<59?( !$r!rI):r3 contextlibrrrlnumbersrrrnumpyr matplotlibrr/rr r r r r rrjrrlinesrpatchesrrrrrrr6rGrfrrr'rprrrr1rLrmr~rrr2r'_RECTANGLESELECTOR_PARAMETERS_DOCSTRING SubstitutionrrrrrrIr4r!rrWs ! $222006#'#'L83Q3Qld(Zd(NK'K'\GIZGITuI*uIp @ n(:n(b A(jA(HH(:H(VE&&E&PT$ZT$nB#&B#Ja"ja"H [?[| k"k"\>*>*DT(p@HH{$%b?b?%b?J@HHy"#%>'%>#%>PHOHVq,oq,h L$JL$r!