rL iLdZddlZddlZddlZddlmZmZddlm Z ddl m Z ddlmZddlmZddlmZddlmZddlmZmZmZddlmZmZmZdZ d Z!d Z"d,d Z#d-d Z$Gd de jJZ&Gdde&Z'Gdde'Z(Gdde'Z)Gdde&Z*Gdde&Z+Gdde&Z,Gdde&Z-Gdde&Z.dZ/Gd d!e.Z0Gd"d#e&Z1Gd$d%e jJejdZ3Gd&d'Z4Gd(d)e4Z5Gd*d+e4Z6y).ac Container classes for `.Artist`\s. `OffsetBox` The base of all container artists defined in this module. `AnchoredOffsetbox`, `AnchoredText` Anchor and align an arbitrary `.Artist` or a text relative to the parent axes or a specific anchor point. `DrawingArea` A container with fixed width and height. Children have a fixed position inside the container and may be clipped. `HPacker`, `VPacker` Containers for layouting their children vertically or horizontally. `PaddedBox` A container to add a padding around an `.Artist`. `TextArea` Contains a single `.Text` instance. N)_api _docstring)FontProperties) BboxImage)FancyBboxPatchFancyArrowPatch bbox_artist)BboxBboxBaseTransformedBboxFcRddgtjfd}|S)z Decorator for the get_offset method of OffsetBox and subclasses, that allows supporting both the new signature (self, bbox, renderer) and the old signature (self, width, height, xdescent, ydescent, renderer). ctSNlocals)selfwidthheightxdescentydescentrenderers Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/offsetbox.pyz$_compat_get_offset..3sfhctSrrrbboxrs rrz$_compat_get_offset..4srctj|g|i|}d|vr|dn%tj|d |d |d|d}|d||dS)Nrrrrrrr)rselect_matching_signaturer from_bounds)rargskwargsparamsrmethsigss r get_offsetz&_compat_get_offset..get_offset6s}//dLTLVL"(F"2v  &"4!4vj7I6I!'&2BD F6ND&*<==r) functoolswraps)r$r&r%s` @r_compat_get_offsetr)-s8 O 1 3D__T>> rc(tr t|i|yyr)DEBUG mbbox_artist)r!r"s r _bbox_artistr-As d%f% rcvtjgd||dk(r=tjdg|Dcgc]}||z c}z}|dd}||d|z }||fS|dk(re|d}t |dkDr|t |z t |dz z }nd}tjdg|Dcgc]}||z c}z}|dd}||fS|d k(ret |}|| td ||zt |z}n|t |z |z }||ztjt |z}||fSycc}wcc}w) a[ Pack boxes specified by their *widths*. For simplicity of the description, the terminology used here assumes a horizontal layout, but the function works equally for a vertical layout. There are three packing *mode*\s: - 'fixed': The elements are packed tight to the left with a spacing of *sep* in between. If *total* is *None* the returned total will be the right edge of the last box. A non-*None* total will be passed unchecked to the output. In particular this means that right edge of the last box may be further to the right than the returned total. - 'expand': Distribute the boxes with equal spacing so that the left edge of the first box is at 0, and the right edge of the last box is at *total*. The parameter *sep* is ignored in this mode. A total of *None* is accepted and considered equal to 1. The total is returned unchanged (except for the conversion *None* to 1). If the total is smaller than the sum of the widths, the laid out boxes will overlap. - 'equal': If *total* is given, the total space is divided in N equal ranges and each box is left-aligned within its subspace. Otherwise (*total* is *None*), *sep* must be provided and each box is left-aligned in its subspace of width ``(max(widths) + sep)``. The total width is then calculated to be ``N * (max(widths) + sep)``. Parameters ---------- widths : list of float Widths of boxes to be packed. total : float or None Intended total length. *None* if not used. sep : float or None Spacing between boxes. mode : {'fixed', 'expand', 'equal'} The packing mode. Returns ------- total : float The total width needed to accommodate the laid out boxes. offsets : array of float The left offsets of the boxes. )fixedexpandequal)moder/rNr0r1z@total and sep cannot both be None when using layout mode 'equal') r check_in_listnpcumsumlensummax ValueErrorarange)widthstotalsepr2woffsets_offsetsmaxhs r_get_packed_offsetsrDFsf\ 3$? w99aSV#<AG#<<=3B- =RL3&Eg~   =E v;?3v;&3v;?;CC99aSV#<AG#<<=3B-g~ 6{ ={ "=>>CZ3v;.E#f+%,C#:3v;!77g~ '$=$=s D1 ( D6 ctjgd||td|D}|dk(r7td|Dtd|Df}dgt |z}||fS|dvrd|f}|Dcgc]\}}|  }}}||fS|d vrd|f}|Dcgc] \}}||z  }}}||fS|d k(r$d|f}|Dcgc]\}}|||z z d z|z }}}fScc}}wcc}}wcc}}w) a Align boxes each specified by their ``(y0, y1)`` spans. For simplicity of the description, the terminology used here assumes a horizontal layout (i.e., vertical alignment), but the function works equally for a vertical layout. Parameters ---------- yspans List of (y0, y1) spans of boxes to be aligned. height : float or None Intended total height. If None, the maximum of the heights (``y1 - y0``) in *yspans* is used. align : {'baseline', 'left', 'top', 'right', 'bottom', 'center'} The alignment anchor of the boxes. Returns ------- (y0, y1) y range spanned by the packing. If a *height* was originally passed in, then for all alignments other than "baseline", a span of ``(0, height)`` is used without checking that it is actually large enough). descent The descent of the packing. offsets The bottom offsets of the boxes. )baselinelefttoprightbottomcenter)alignc3,K|] \}}||z ywr.0y0y1s r z'_get_aligned_offsets..s2RR"W2srFc3&K|] \}}| ywrrNrOs rrSz'_get_aligned_offsets..s-FBR-c3&K|] \}}| ywrrNrOs rrSz'_get_aligned_offsets..s2K&"b22KrUr)rGrJ)rIrHrK?)rr5r:minr8)yspansrrLyspanrBrQrRs r_get_aligned_offsetsr[s<< @O ~2622 -f--s2KF2K/KL#F # '> $ $F %+,62rB3,, '> " "F -3462r6B;44 '> ( F @FGfb"Fb2g&",r1GG '>-5Hs7 CC!<C'ceZdZdZfdZfdZejjjdZdZ dZ e dZ dZd Zd Zd Zd Zd ZddZdZxZS) OffsetBoxz A simple container artist. The child artists are meant to be drawn at a relative position to its parent. Being an artist itself, all parameters are passed on to `.Artist`. c~t|||j||jdg|_d|_y)NFrr)super__init___internal_update set_clip_on _children_offset)rr!r" __class__s rrazOffsetBox.__init__s< $ f%  rcpt|||jD]}|j|y)z Set the `.Figure` for the `.OffsetBox` and all its children. Parameters ---------- fig : `~matplotlib.figure.Figure` N)r` set_figure get_children)rfigcrfs rrhzOffsetBox.set_figures6 3""$ A LL  rctjjj|||j D] }|||_yr)martistArtistaxesfsetri)raxrks rrozOffsetBox.axessB   r*""$ A} rc|j|rdifS|jD]}|j|\}}|s||fcSdifS)a Delegate the mouse event contains-check to the children. As a container, the `.OffsetBox` does not respond itself to mouseevents. Parameters ---------- mouseevent : `~matplotlib.backend_bases.MouseEvent` Returns ------- contains : bool Whether any values are within the radius. details : dict An artist-specific dictionary of details of the event context, such as which points are contained in the pick radius. See the individual Artist subclasses for details. See Also -------- .Artist.contains F)_different_canvasricontains)r mouseeventrkabs rrtzOffsetBox.containss^0  ! !* -"9 ""$ A::j)DAq!t  byrc ||_d|_y)a Set the offset. Parameters ---------- xy : (float, float) or callable The (x, y) coordinates of the offset in display units. These can either be given explicitly as a tuple (x, y), or by providing a function that converts the extent into the offset. This function must have the signature:: def offset(width, height, xdescent, ydescent, renderer) -> (float, float) TN)restalerxys r set_offsetzOffsetBox.set_offsets  rct|jr?|j|j|j|j |j |S|jS)aO Return the offset as a tuple (x, y). The extent parameters have to be provided to handle the case where the offset is dynamically determined by a callable (see `~.OffsetBox.set_offset`). Parameters ---------- bbox : `.Bbox` renderer : `.RendererBase` subclass )callablererrx0rQrs rr&zOffsetBox.get_offset#sM  % LLT[[477(TWWHh O  rc ||_d|_y)zh Set the width of the box. Parameters ---------- width : float TN)rry)rrs r set_widthzOffsetBox.set_width6s  rc ||_d|_y)zj Set the height of the box. Parameters ---------- height : float TN)rry)rrs r set_heightzOffsetBox.set_heightAs  rcb|jDcgc]}|js|c}Scc}w)z/Return a list of the visible child `.Artist`\s.)rd get_visible)rrks rget_visible_childrenzOffsetBox.get_visible_childrenLs">>=aQ]]_===s,,c|jS)z'Return a list of the child `.Artist`\s.)rdrs rrizOffsetBox.get_childrenP ~~rctd)a/ Return the bbox of the offsetbox and the child offsets. The bbox should satisfy ``x0 <= x1 and y0 <= y1``. Parameters ---------- renderer : `.RendererBase` subclass Returns ------- bbox list of (xoffset, yoffset) pairs z:get_bbox_and_offsets must be overridden in derived classes)NotImplementedErrorrrs r_get_bbox_and_child_offsetsz%OffsetBox._get_bbox_and_child_offsetsTs" HJ Jrc.|j|\}}|S)z:Return the bbox of the offsetbox, ignoring parent offsets.)r)rrrrBs rget_bboxzOffsetBox.get_bboxfs88B g rc| |jdj}|j|} |j||\}}|j ||S#t$r|j\}}Y0wxYwNTroot) get_figure _get_rendererrr& TypeError translated)rrrpxpys rget_window_extentzOffsetBox.get_window_extentks|  D1??AH}}X& '__T84FBr2&& '__&FB 'sAA;:A;c4|j|\}}|j||\}}t|j|D]2\}\}}|j ||z||zf|j |4t ||dtdd|_y)zm Update the location of children if necessary and draw them to the given *renderer*. FpadfillpropsN) rr&ziprr|drawr-dictry rrrrBrrrkoxoys rrzOffsetBox.drawvs 88B gx0Bt88:GD KAxB LL"r'27+ , FF8   T8%t|D rr)__name__ __module__ __qualname____doc__rarhrmrnrosetterrtr|r)r&rrrrirrrr __classcell__rfs@rr]r]s~  ^^ @$$  >J$ ' rr]c$eZdZ dfd ZxZS) PackerBasect|||_||_||_||_||_||_||_y)ao Parameters ---------- pad : float, default: 0.0 The boundary padding in points. sep : float, default: 0.0 The spacing between items in points. width, height : float, optional Width and height of the container box in pixels, calculated if *None*. align : {'top', 'bottom', 'left', 'right', 'center', 'baseline'}, default: 'baseline' Alignment of boxes. mode : {'fixed', 'expand', 'equal'}, default: 'fixed' The packing mode. - 'fixed' packs the given `.Artist`\s tight with *sep* spacing. - 'expand' uses the maximal available space to distribute the artists with equal spacing in between. - 'equal': Each artist an equal fraction of the available space and is left-aligned (or top-aligned) therein. children : list of `.Artist` The artists to pack. Notes ----- *pad* and *sep* are in points and will be scaled with the renderer dpi, while *width* and *height* are in pixels. N) r`rarrr?rr2rLrd) rrr?rrrLr2childrenrfs rrazPackerBase.__init__sBH     !r)rrNNrFr/N)rrrrarrs@rrrs:>:>+"+"rrceZdZdZdZy)VPackerz VPacker packs its children vertically, automatically adjusting their relative positions at draw time. .. code-block:: none +---------+ | Child 1 | | Child 2 | | Child 3 | +---------+ cX|jd}|j|z}|j|z}|jQ|j D]>}t |t s|jdk(s$|j|j@|j Dcgc]}|j|}}t|Dcgc]}|jc}|j|j\\}} } t|Dcgc]}|jc}|j||j\} } | | |Dcgc]}|jc}zz } | d} | | z } t!j"|| | |z | j%|gt'| | fScc}wcc}wcc}wcc}w)N?r0r)points_to_pixelsrr?rr isinstancerr2rrr[ intervalxrLrDrrRr r paddedr)rrdpicorrr?rkbboxesrrx1xoffsetsryoffsetsrs rrz#VPacker._get_bbox_and_child_offsetss**2.hhhh :: !..0 ,a,81CKK + ,150I0I0KL1!**X&LL1(. /T^^ /TZZIR(.%+ ,TT[[ ,dkk3 KXV(DT(DDEA;h&   R(BGV < C CC H &c(H% &( (M / ,(DsFFF";F'NrrrrrrNrrrrs  (rrceZdZdZdZy)HPackera  HPacker packs its children horizontally, automatically adjusting their relative positions at draw time. .. code-block:: none +-------------------------------+ | Child 1 Child 2 Child 3 | +-------------------------------+ c|jd}|j|z}|j|z}|jDcgc]}|j |}}|s)t j ddddj|gfSt|Dcgc]}|jc}|j|j\\}} } t|Dcgc]}|jc}|j||j\} } |dj} | |Dcgc]}|jc}| z z} t j | || | |z j|gt!| | fScc}wcc}wcc}wcc}w)Nrr)rrr?rrr r rr[ intervalyrrLrDrr2rr)rrrrr?rkrrrQrRrrrrs rrz#HPacker._get_bbox_and_child_offsetssZ**2.hhhh040I0I0KL1!**X&LL##Aq!Q/66s;R? ?1(. /T^^ /djjJR(-$* +DTZZ +TZZdiiIxAY\\&1$dgg1B67  RR8??D*#h)*, ,M 0 +2sE*E/E4E9NrrNrrrrs  ,rrcFeZdZdZd dddfd ZdZdZd dZd ZxZ S) PaddedBoxa A container to add a padding around an `.Artist`. The `.PaddedBox` contains a `.FancyBboxPatch` that is used to visualize it when rendering. .. code-block:: none +----------------------------+ | | | | | | | <--pad--> Artist | | ^ | | pad | | v | +----------------------------+ Attributes ---------- pad : float The padding in points. patch : `.FancyBboxPatch` When *draw_frame* is True, this `.FancyBboxPatch` is made visible and creates a border around the box. FN) draw_frame patch_attrsc t|||_|g|_t ddddddd|d |_||j j |y y ) a Parameters ---------- child : `~matplotlib.artist.Artist` The contained `.Artist`. pad : float, default: 0.0 The padding in points. This will be scaled with the renderer dpi. In contrast, *width* and *height* are in *pixels* and thus not scaled. draw_frame : bool Whether to draw the contained `.FancyBboxPatch`. patch_attrs : dict or None Additional parameters passed to the contained `.FancyBboxPatch`. rrrr@kr4T square,pad=0 r{rr facecolor edgecolormutation_scalesnapvisibleboxstyleN)r`rarrdrpatchupdate)rchildrrrrfs rrazPaddedBox.__init__sc #BS#     " JJ  k * #rc|j|jdz}|jdj|j |dgfS)Nrrr_)rrrdrr)rrrs rrz%PaddedBox._get_bbox_and_child_offsets6sGhh22266q!**84;;C@6(KKrcN|j|\}}|j||\}}t|j|D]!\}\}}|j ||z||zf#|j ||jD]}|j |d|_yNF)rr&rrr|rrryrs rrzPaddedBox.draw;s88B gx0Bt88:GD -KAxB LL"r'27+ , - !**, A FF8   rc|jj|j|r|jj|d|_yNT)r set_boundsboundsset_mutation_scaleryrrfontsizes r update_framezPaddedBox.update_frameIs4 dkk*  JJ ) )( 3 rcz|j|j||jj|yr)rrrrrs rrzPaddedBox.draw_frameOs+ $00:; !r)rr) rrrrrarrrrrrs@rrrs+6+Et+:L  "rrceZdZdZd fd ZedZejdZdZdZ dZ dZ d Z d Z d ZxZS) DrawingAreaz The DrawingArea can contain any Artist as a child. The DrawingArea has a fixed width and height. The position of children relative to the parent is fixed. The children can be clipped at the boundaries of the parent. ct|||_||_||_||_||_tj|_ tj|_ y)a" Parameters ---------- width, height : float Width and height of the container box. xdescent, ydescent : float Descent of the box in x- and y-direction. clip : bool Whether to clip the children to the box. N) r`rarrrr_clip_children mtransformsAffine2Doffset_transform dpi_transform)rrrrrcliprfs rrazDrawingArea.__init__]sV       " + 4 4 6(113rc|jS)zl If the children of this DrawingArea should be clipped by DrawingArea bounding box. )rrs r clip_childrenzDrawingArea.clip_childrenqs """rc2t||_d|_yr)boolrry)rvals rrzDrawingArea.clip_childrenys"3i rc4|j|jzS)zX Return the `~matplotlib.transforms.Transform` applied to the children. )rrrs r get_transformzDrawingArea.get_transform~s!!D$9$999rcyz+ set_transform is ignored. NrNrts r set_transformzDrawingArea.set_transformrc||_|jj|jj|d|dd|_yz Set the offset of the container. Parameters ---------- xy : (float, float) The (x, y) coordinates of the offset in display units. rr4TNrerclear translateryrzs rr|zDrawingArea.set_offsetB  ##% ''1r!u5 rc|jSzReturn offset of the container.rers rr&zDrawingArea.get_offset ||rc|jd}tj|j |z|j |z|j |z|j |zS)Nr)rr r rrrr)rrdpi_cors rrzDrawingArea.get_bboxsW++B/ ]]NW $t}}nw&> JJ $++"79 9rc|jj||js|j|j |j |j |_|j d}||j|yy)&Add an `.Artist` to the container box.NFr)rdappendis_transform_setrrrorrh)rrvrjs r add_artistzDrawingArea.add_artistsp a !!# OOD..0 1 99 YYAFoo5o) ? LL  rc T|jd}|jj|jj|t j t jddgd|jg|j|jg|jdgg|j}|jD]H}|jr)|js|js|j||j!|Jt#||dt%dd|_y)NrrFrrr)rrrscalerTransformedPathmpathPathrrrrdrclipbox _clippath set_clip_pathrr-rry)rrrtpathrks rrzDrawingArea.draws++B/   "   ) ++ JJADKK 0T[[1Q) *    "  A""AII& FF8   T8%t|D r)rrF)rrrrrapropertyrrrrr|r&rr rrrs@rrrUs^4(##:  9 rrc`eZdZdZdddfd ZdZdZdZd Zd Z d Z d Z d Z dZ xZS)TextAreaz The TextArea is a container artist for a single Text instance. The text is placed at (0, 0) with baseline+left alignment, by default. The width and height of the TextArea instance is the width and height of its child text. NF) textpropsmultilinebaselinec^|i}tjdd|fi||_t||jg|_t j|_t j|_ |jj|j|jz||_ y)a Parameters ---------- s : str The text to be displayed. textprops : dict, default: {} Dictionary of keyword parameters to be passed to the `.Text` instance in the TextArea. multilinebaseline : bool, default: False Whether the baseline for multiline text is adjusted so that it is (approximately) center-aligned with single-line text. Nr) mtextText_textr`rardrrr_baseline_transformr_multilinebaseline)rsrrrfs rrazTextArea.__init__s"  IZZ1a595  ** + 4 4 6#.#7#7#9    !6!6!%!9!9": ;"3rcH|jj|d|_y)z&Set the text of this area as a string.TN)rset_textryrrs rr zTextArea.set_texts A rc6|jjS)z5Return the string representation of this area's text.)rget_textrs rr#zTextArea.get_textszz""$$rc ||_d|_y)aX Set multilinebaseline. If True, the baseline for multiline text is adjusted so that it is (approximately) center-aligned with single-line text. This is used e.g. by the legend implementation so that single-line labels are baseline-aligned, but multiline labels are "center"-aligned with them. TN)rryrs rset_multilinebaselinezTextArea.set_multilinebaselines#$ rc|jS)z( Get multilinebaseline. )rrs rget_multilinebaselinezTextArea.get_multilinebaselines&&&rcyrrNrs rrzTextArea.set_transformrrc||_|jj|jj|d|dd|_yrrrzs rr|zTextArea.set_offset rrc|jSrrrs rr&zTextArea.get_offsetrrc tj|d|jj|jj rdnd|j dj \}}}|jj|\}}}|j\}} |jjt|dkDr<|jr0d| zd||z zz } |jjd || z | }nt||z | |z } | |z} |jj} d | d z | d | } t!j"| | || S) NlpTeXFTr)ismathdpir4rWr)rGrKrI)r_get_text_metrics_with_cacher_fontproperties get_usetexrr/ _get_layoutsizerrr8rrr:get_horizontalalignmentr r )rr_h_d_rinfoydr@hyd_newh_dhars rrzTextArea.get_bboxs566 dDJJ66 JJ1135T*..0 2r //9dByy1   &&( t9q=T441Wsb2g.F  $ $ . .q"v+ >Bb2gq2v&CbA ZZ / / 1A26QB 7 ;RCA..rcz|jj|t||dtdd|_yNFrrr)rrr-rryrs rrz TextArea.draw4s+ !T8%t|D r)rrrrrar r#r%r'rr|r&rrrrs@rrrsB #(48 % '  /0rrcLeZdZdZfdZdZdZdZdZdZ dZ d Z xZ S) AuxTransformBoxa An OffsetBox with an auxiliary transform. All child artists are first transformed with *aux_transform*, then translated with an offset (the same for all children) so the bounding box of the children matches the drawn box. (In other words, adding an arbitrary translation to *aux_transform* has no effect as it will be cancelled out by the later offsetting.) `AuxTransformBox` is similar to `.DrawingArea`, except that the extent of the box is not predetermined but calculated from the window extent of its children, and the extent of the children will be calculated in the transformed coordinate. c||_t| tj|_tj|_yr) aux_transformr`rarrrref_offset_transform)rrErfs rrazAuxTransformBox.__init__Js:*  + 4 4 6%0$8$8$:!rc|jj||j|jd|_y)rTN)rdrrrry)rrvs rr zAuxTransformBox.add_artistRs0 a  **,- rcN|j|jz|jzS)z0Return the `.Transform` applied to the children.)rErFrrs rrzAuxTransformBox.get_transformXs,""++,''( )rcyrrNrs rrzAuxTransformBox.set_transform^rrc||_|jj|jj|d|dd|_yrrrzs rr|zAuxTransformBox.set_offsetcrrc|jSrrrs rr&zAuxTransformBox.get_offsetqrrc|jj}|jj|jj|jDcgc]}|j |}}t j|}|jj|j |j |jj|t jdd|j|jScc}wNr)r get_matrixrFrrdrr unionrrrQ set_matrixr rr)rr_offrkrubs rrzAuxTransformBox.get_bboxus$$//1 !!'') ##%9=HA!%%h/HH ZZ  !!++RUUFRUUF; ((.1bhh :: IsDc|jD]}|j|t||dtdd|_yrA)rdrr-rry)rrrks rrzAuxTransformBox.draws: A FF8  T8%t|D r) rrrrrar rrr|r&rrrrs@rrCrC;s0 ; )   ;rrCc eZdZdZdZdddddddd d d d Zd dddddddfd ZdZdZdZ dZ dZ ddZ e dZddZdZxZS)AnchoredOffsetboxa/ An OffsetBox placed according to location *loc*. AnchoredOffsetbox has a single child. When multiple children are needed, use an extra OffsetBox to enclose them. By default, the offset box is anchored against its parent Axes. You may explicitly specify the *bbox_to_anchor*. r4r0 ) z upper rightz upper leftz lower leftz lower rightrIz center leftz center rightz lower centerz upper centerrK皙?rWNT)r borderpadrpropframeonbbox_to_anchorbbox_transformc Vt |d i| |j|||j|t |t r!t j|j|}||_ ||_ ||_ |#ttjd|_nZtj ||_t |t"r0d|vr,|jj%tjdt'ddddd |jj)d |d |_y)a Parameters ---------- loc : str The box location. Valid locations are 'upper left', 'upper center', 'upper right', 'center left', 'center', 'center right', 'lower left', 'lower center', 'lower right'. For backward compatibility, numeric values are accepted as well. See the parameter *loc* of `.Legend` for details. pad : float, default: 0.4 Padding around the child as fraction of the fontsize. borderpad : float, default: 0.5 Padding between the offsetbox frame and the *bbox_to_anchor*. child : `.OffsetBox` The box that will be anchored. prop : `.FontProperties` This is only used as a reference for paddings. If not given, :rc:`legend.fontsize` is used. frameon : bool Whether to draw a frame around the box. bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats Box that is used to position the legend in conjunction with *loc*. bbox_transform : None or :class:`matplotlib.transforms.Transform` The transform for the bounding box (*bbox_to_anchor*). **kwargs All other parameters are passed on to `.OffsetBox`. Notes ----- See `.Legend` for a detailed description of the anchoring mechanism. )locNlegend.fontsizer5r5rrr@rTrrrN)r`raset_bbox_to_anchor set_childrstrr check_getitemcodesrer_rrmplrcParamsr` _from_anyrset_sizerget_size_in_pointsr) rrerr_rr`rarbrcr"rfs rrazAnchoredOffsetbox.__init__sL "6" ? u c3 $$TZZS9C" <&CLL9J,KLDI&006DI$%&*< ""3<<0A#BC#BS99779#   rcF||_||j|_d|_y)zSet the child to be anchored.NT)_childrory)rrs rrizAnchoredOffsetbox.set_childs!  EJ rc|jS)zReturn the child.rsrs r get_childzAnchoredOffsetbox.get_childs {{rc|jgS)zReturn the list of children.rurs rrizAnchoredOffsetbox.get_childrens }rc|j|jj}|j|z}|j j |j |Sr)rr`rqrrvrr)rrrrs rrzAnchoredOffsetbox.get_bboxsP,,TYY-I-I-KLhh!~~((299#>>rc|j|jjS|j}| |jSt |j|S)z,Return the bbox that the box is anchored to.)_bbox_to_anchorror_bbox_to_anchor_transformr )r transforms rget_bbox_to_anchorz$AnchoredOffsetbox.get_bbox_to_anchorsL    '99>> !66I +++&t';';YGGrc|t|tr||_n4 t|}|dk(r |d|dddg}t j||_||_d|_ y#t$r}t d||d}~wwxYw)aB Set the bbox that the box is anchored to. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. NzInvalid bbox: r0rr4T) rr rzr8rr;r r r{ry)rrr|lerrs rrhz$AnchoredOffsetbox.set_bbox_to_anchors <:dH5#'D  CIAvQa!Q/#'#3#3T#:D )2&  C >$!89sB Cs A A;'A66A;c T|j|j|jjz}|j }t |j tjdd|j|j||\}}||jz ||jz fSrM) r_rr`rqr}_get_anchored_bboxrer r rrrrQ)rrrrrbrrQs rr&zAnchoredOffsetbox.get_offsets~~**499+G+G+IJK002# HHd&&q!TZZE C!BDGG|R$''\))rc|jj|j|r|jj|yyr)rrrrrs rrzAnchoredOffsetbox.update_frame)s2 dkk*  JJ ) )( 3 rc|jsy|j|}|j|jj }|j |||j j||j|j||\}}|jj||f|jj|d|_ yr) rrrr`rqrrrr&rrvr|ry)rrrrrrs rrzAnchoredOffsetbox.draw.s! %%h/,,TYY-I-I-KL $) !x!8(CB ##RH- h' rr)rrrrzorderrlrarirvrirr}rhr)r&rrrrs@rrUrUsF EC$ $ $ @ D? H2**4 rrUcngd|}|j| }|j||jS)z} Return the (x, y) position of the *bbox* anchored at the *parentbbox* with the *loc* code with the *borderpad*. ) NNENWSWSEEWrSNC) container)ranchoredp0)rer parentbboxr_rkrs rrr?s: ESIA!!9*-I ==i= 0 3 33rc,eZdZdZddddfd ZxZS) AnchoredTextz& AnchoredOffsetbox with Text. r^rWN)rr_r`c |i}ddh}|t|zr tdt|||_|jjj }t ||f|||j|d|y)aq Parameters ---------- s : str Text. loc : str Location code. See `AnchoredOffsetbox`. pad : float, default: 0.4 Padding around the text as fraction of the fontsize. borderpad : float, default: 0.5 Spacing between the offsetbox frame and the *bbox_to_anchor*. prop : dict, optional Dictionary of keyword parameters to be passed to the `~matplotlib.text.Text` instance contained inside AnchoredText. **kwargs All other parameters are passed to `AnchoredOffsetbox`. Nvaverticalalignmentz >=A4c| |jdj}|j|tj|j Dcgc]}|j |c}Scc}wr)rrrr rOri get_tightbboxrs rrzAnnotationBbox.get_tightbboxuso  D1??AH h'zz(,(9(9(;=$!..x8=> >=rc|j||j|j\}}|jj |}|j \}}|jj |||jzz |jz |||jzz |jz f|jj|}|jj|j|j|j!}|jj#||j$r|j&|j(|j*zz}|j-|} |j.j1|| d|j$vr|j|j$d}|j.j#||j$j3d|j} |j.j5| yy)zHUpdate pixel positions for the annotated point, the text, and the arrow.rpatchAN)_get_xyrrrrrr|rrrrQrrrrrrrrrr5r_get_position_xyr set_positionsget set_patchA) rrox0oy0rfwfhr arrow_begin arrow_endrs rrzAnnotationBbox.update_positions}s<<$**dnnES~~&&x0$$B !! 2djj= 477 *C"T[[.,@477,J K M~~//9 dkk*!2243D3D3FG %%n5 ?? ''DII0B0B$BBK--h7I    * *; B4??2!)!:!:OO$45"7    / / ?__((4::>F    ' ' /' rc||jr|j|sy|j|jj|j |j ||jf|jjd/|jdx}|jj||jj||jj||jj||j|jjd|_y)N)gidFr)rr open_grouprfrget_gidrrrrhrrr close_groupry)rrrjs rrzAnnotationBbox.draws!)A DNN33H h'    '  +++7? OOO77SD  ++C0    ! !( + ! H%T^^445 r)NrNr)rrrrrrrinterpdrarrrrrtrirhrrrrrrrNrrrrsF@i&3!%)  i&i&V \\3 - .>>"0Hrrc|eZdZdZddZedZedZedZ dZ dZ dZ d Z d Zd Zd Zd Zy) DraggableBasea Helper base class for a draggable artist (legend, offsetbox). Derived classes must override the following methods:: def save_offset(self): ''' Called when the object is picked for dragging; should save the reference position of the artist. ''' def update_offset(self, dx, dy): ''' Called during the dragging; (*dx*, *dy*) is the pixel offset from the point where the mouse drag started. ''' Optionally, you may override the following method:: def finalize_offset(self): '''Called when the mouse is released.''' In the current implementation of `.DraggableLegend` and `DraggableAnnotation`, `update_offset` places the artists in display coordinates, and `finalize_offset` recalculates their position in axes coordinate and set a relevant attribute. c ||_|js|j|jd|_|xr|j j |_|j j}d|jfd|jfd|jffDcgc]5\}}tj|j|j||7c}}|_ycc}}w)NF pick_eventbutton_release_eventmotion_notify_event) ref_artistpickable set_picker_picker got_artistcanvas supports_blit _use_blit callbackson_pick on_release on_motionr'partial disconnect_connect_picklable_disconnectors)rruse_blitrnamefuncs rrazDraggableBase.__init__s$""$  ! !$,, /!?dkk&?&?KK)) t||,'9&7 d   $$i&B&B4&N P  s:CcJ|jdk(rdifS|j|S)N scroll_eventF)rrt)artistrus rr zDraggableBase._pickers) ??n ,"9 z**rcN|jjdjSr)rrr rs rrzDraggableBase.s4??#=#=4#=#H#O#Orc`|jddDcgc]}|jdc}Scc}w)Nr0r)rr!)rrs rrzDraggableBase.s5-1-@-@!-D"F) "F"Fs+c|jr|jr|j|jz }|j|j z }|j |||jr|jj|j|jj|jjdj|jjy|jjyyyr)_check_still_parentedr xmouse_xymouse_y update_offsetrr restore_region backgroundrrrrblit)revtdxdys rrzDraggableBase.on_motions  % % 'DOO%B%B   r2 &~~ **4??;$$OO..D.9GGIK   "   "-< 'rc|jr?|j|jk(rM|jj|_|jj |_|jd|_ |jr|jr|jjd|jj|jjd}|jj|j |_|jj|j%|jj'yyyy)NTFr)r!rrrur"r#r$r% save_offsetr r set_animatedr rrcopy_from_bboxrr(rr))rr*rjs rrzDraggableBase.on_picks  % % 'zzT__,"~~// "~~//   ""&4>>,,T2   "oo00e0<"&++"<"r_sA0'#+2&BBAA (& Nb0fwwt,","^%(j%(P,j,DU" U"pm)m`syslMiM`q qh 4($(VD)DNrW^^U%:%:rjs s l2 *- *r