
    h                     P   S r SSKrSSKrSSKrSSKJrJr  SSKJ	r
  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SSKJrJrJr  Sr S	 r!S
 r"S,S jr#S-S jr$ " S S\
RJ                  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      r.S r/ " S  S!\.5      r0 " S" S#\&5      r1 " S$ S%\
RJ                  \Rd                  5      r3 " S& S'5      r4 " S( S)\45      r5 " S* S+\45      r6g).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)FancyBboxPatchFancyArrowPatchbbox_artist)BboxBboxBaseTransformedBboxFc                 V   ^ ^ S S /m[         R                  " T 5      U U4S j5       nU$ )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).
c                     [        5       $ Nlocals)selfwidthheightxdescentydescentrenderers         F/var/www/html/env/lib/python3.13/site-packages/matplotlib/offsetbox.py<lambda>$_compat_get_offset.<locals>.<lambda>3   s    fh    c                     [        5       $ r   r   r   bboxr   s      r   r   r   4   s    r   c                    > [         R                  " TU /UQ70 UD6nSU;   a  US   O&[        R                  " US   * US   * US   US   5      nT" US   XCS   5      $ )Nr   r   r   r   r   r   r   )r   select_matching_signaturer
   from_bounds)r   argskwargsparamsr   methsigss        r   
get_offset&_compat_get_offset.<locals>.get_offset6   s{    //dLTLVL"(F"2v  &"4!4vj7I6I!'&2BD 	 F6ND*<==r   )	functoolswraps)r%   r'   r&   s   ` @r   _compat_get_offsetr+   -   s8     O13D __T> > r   c                  2    [         (       a  [        U 0 UD6  g g r   )DEBUGmbbox_artist)r"   r#   s     r   _bbox_artistr/   A   s    ud%f% r   c                    [         R                  " / SQUS9  US:X  a@  [        R                  " S/U  Vs/ s H  oDU-   PM	     sn-   5      nUSS nUc  US   U-
  nX4$ US:X  ai  Uc  Sn[	        U 5      S:  a  U[        U 5      -
  [	        U 5      S-
  -  nOSn[        R                  " S/U  Vs/ s H  oDU-   PM	     sn-   5      nUSS nX4$ US	:X  ae  [        U 5      nUc  Uc  [        S
5      eXr-   [	        U 5      -  nOU[	        U 5      -  U-
  nXr-   [        R                  " [	        U 5      5      -  nX4$ gs  snf s  snf )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.
)fixedexpandequal)moder1   r   Nr2      r3   z@total and sep cannot both be None when using layout mode 'equal')	r   check_in_listnpcumsumlensummax
ValueErrorarange)widthstotalsepr4   woffsets_offsetsmaxhs           r   _get_packed_offsetsrF   F   s`   \ 	3$?w99aSV#<VGV#<<=3B-=RL3&E~		 =Ev;?3v;&3v;?;CC99aSV#<VGV#<<=3B-~	6{={  "= > >Z3v;.E#f+%,C:3v;!77~ 
' $= $=s   D9
.D>
c                    [         R                  " / SQUS9  Uc  [        S U  5       5      nUS:X  a6  [        S U  5       5      [        S U  5       5      4nS/[	        U 5      -  nX44$ US;   a  SU4nU  VVs/ s H  u  pVU* PM
     nnnX44$ US	;   a  SU4nU  VVs/ s H	  u  pVX-
  PM     nnnX44$ US
:X  a%  SU4nU  VVs/ s H  u  pVXU-
  -
  S-  U-
  PM     nnnWW4$ s  snnf s  snnf s  snnf )ad  
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.
)baselinelefttoprightbottomcenter)alignc              3   .   #    U  H  u  pX!-
  v   M     g 7fr    .0y0y1s      r   	<genexpr>'_get_aligned_offsets.<locals>.<genexpr>   s     26RW6s   rH   c              3   *   #    U  H	  u  pUv   M     g 7fr   rP   rQ   s      r   rU   rV      s     -fFBRf   c              3   *   #    U  H	  u  pUv   M     g 7fr   rP   rQ   s      r   rU   rV      s     2KF&"2FrX   r   )rI   rL   )rK   rJ   rM         ?)r   r7   r<   minr:   )yspansr   rN   yspanrD   rS   rT   s          r   _get_aligned_offsetsr^      s/   < 	@O~2622
-f--s2KF2K/KL#F# > 
$	$F%+,V62B3V, > 
"	"F-34V626;V4
 >	 
(	F@FGfbF2g&",r1G'> - 5 Hs   8C!C'C-c                      ^  \ rS rSrSrU 4S jrU 4S jr\R                  R                  R                  S 5       r	S rS r\S 5       rS	 rS
 rS rS rS rS rSS jrS rSrU =r$ )	OffsetBox   z
The OffsetBox is 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U ]  " U6   U R                  U5        U R                  S5        / U l        SU l        g )NFr   r   )super__init___internal_updateset_clip_on	_children_offset)r   r"   r#   	__class__s      r   re   OffsetBox.__init__   s<    $f% 	r   c                 t   > [         TU ]  U5        U R                  5        H  nUR                  U5        M     g)zw
Set the `.Figure` for the `.OffsetBox` and all its children.

Parameters
----------
fig : `~matplotlib.figure.Figure`
N)rd   
set_figureget_children)r   figcrj   s      r   rm   OffsetBox.set_figure   s1     	3""$ALL %r   c                     [         R                  R                  R                  X5        U R	                  5        H  nUc  M  Xl        M     g r   )martistArtistaxesfsetrn   )r   axrp   s      r   ru   OffsetBox.axes   s9     	  *""$A} %r   c                     U R                  U5      (       a  S0 4$ U R                  5        H"  nUR                  U5      u  p4U(       d  M  X44s  $    S0 4$ )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_canvasrn   contains)r   
mouseeventrp   abs        r   r{   OffsetBox.contains   sZ    0 !!*--"9""$A::j)DAqt % byr   c                     Xl         SU l        g)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)ri   staler   xys     r   
set_offsetOffsetBox.set_offset  s     
r   c                     [        U R                  5      (       a?  U R                  UR                  UR                  UR                  * UR
                  * U5      $ U R                  $ )a  
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
)callableri   r   r   x0rS   r   s      r   r'   OffsetBox.get_offset#  sP      %% LLT[[477(TWWHhO	 	r   c                     Xl         SU l        g)z@
Set the width of the box.

Parameters
----------
width : float
TN)r   r   )r   r   s     r   	set_widthOffsetBox.set_width6  s     

r   c                     Xl         SU l        g)zB
Set the height of the box.

Parameters
----------
height : float
TN)r   r   )r   r   s     r   
set_heightOffsetBox.set_heightA  s     
r   c                 r    U R                    Vs/ s H  oR                  5       (       d  M  UPM     sn$ s  snf )z/Return a list of the visible child `.Artist`\s.)rh   get_visible)r   rp   s     r   get_visible_childrenOffsetBox.get_visible_childrenL  s$    >>=>a]]_>===s   44c                     U R                   $ )z'Return a list of the child `.Artist`\s.)rh   r   s    r   rn   OffsetBox.get_childrenP      ~~r   c                     [        S5      e)z
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)NotImplementedErrorr   r   s     r   _get_bbox_and_child_offsets%OffsetBox._get_bbox_and_child_offsetsT  s     "HJ 	Jr   c                 ,    U R                  U5      u  p#U$ )z:Return the bbox of the offsetbox, ignoring parent offsets.)r   )r   r   r   rD   s       r   get_bboxOffsetBox.get_bboxf  s    88Br   c                     Uc  U R                  SS9R                  5       nU R                  U5      n U R                  X!5      u  p4UR                  X45      $ ! [         a    U R                  5       u  p4 N/f = fNTroot)
get_figure_get_rendererr   r'   	TypeError
translated)r   r   r   pxpys        r   get_window_extentOffsetBox.get_window_extentk  sv    D1??AH}}X&	'__T4FB r&&  	'__&FB	's   A A65A6c           	         U R                  U5      u  p#U R                  X!5      u  pE[        U R                  5       U5       H0  u  nu  pxUR	                  XG-   XX-   45        UR                  U5        M2     [        XS[        SS9S9  SU l        g)zU
Update the location of children if necessary and draw them
to the given *renderer*.
F        padfillpropsN)	r   r'   zipr   r   drawr/   dictr   	r   r   r   rD   r   r   rp   oxoys	            r   r   OffsetBox.drawv  s    
 88B0t88:GDKAxLL"'27+,FF8 E 	T%t|D
r   )rh   ri   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__re   rm   rs   rt   ru   setterr{   r   r+   r'   r   r   r   rn   r   r   r   r   __static_attributes____classcell__rj   s   @r   r`   r`      s    
 ^^  @$  $		>J$
	' r   r`   c                   0   ^  \ rS rSr  SU 4S jjrSrU =r$ )
PackerBasei  c                 v   > [         TU ]  5         X@l        X0l        X l        Xl        X`l        XPl        Xpl        g)a  
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)	rd   re   r   r   rA   r   r4   rN   rh   )	r   r   rA   r   r   rN   r4   childrenrj   s	           r   re   PackerBase.__init__  s4    H 	
	
!r   )rh   rN   r   r4   r   rA   r   )r   r   NNrH   r1   N)r   r   r   r   re   r   r   r   s   @r   r   r     s    :>:>+" +"r   r   c                       \ rS rSrSrS rSrg)VPackeri  z
VPacker packs its children vertically, automatically adjusting their
relative positions at draw time.

.. code-block:: none

   +---------+
   | Child 1 |
   | Child 2 |
   | Child 3 |
   +---------+
c                 p   UR                  S5      nU R                  U-  nU R                  U-  nU R                  b[  U R	                  5        HG  n[        U[        5      (       d  M  UR                  S:X  d  M,  UR                  U R                  5        MI     U R	                  5        Vs/ s H  oUR                  U5      PM     nn[        U Vs/ s H  owR                  PM     snU R                  U R                  5      u  u  pn
[        U Vs/ s H  owR                  PM     snU R                  X@R                  5      u  pXU Vs/ s H  owR                  PM     sn-   -
  nUS   nX-
  n[         R"                  " X* X-
  U5      R%                  U5      / ['        X5      Q4$ s  snf s  snf s  snf s  snf )N      ?r2   r   )points_to_pixelsr   rA   r   r   
isinstancer   r4   r   r   r^   	intervalxrN   rF   r   rT   r
   r!   paddedr   )r   r   dpicorr   rA   rp   bboxesr   r   x1xoffsetsr   yoffsetsr   s                 r   r   #VPacker._get_bbox_and_child_offsets  su   **2.hhhh::!..0a,,81CKK

+ 1 150I0I0KL0K1**X&0KL1(./^^/TZZI(.%+,VT[[V,dkk3		K V(DVTV(DDEA;& RBGV<CCCH&c(%&( 	( M/,(Ds   *F$F)F.F3rP   Nr   r   r   r   r   r   r   rP   r   r   r   r     s    (r   r   c                       \ rS rSrSrS rSrg)HPackeri  z
HPacker packs its children horizontally, automatically adjusting their
relative positions at draw time.

.. code-block:: none

   +-------------------------------+
   | Child 1    Child 2    Child 3 |
   +-------------------------------+
c                    UR                  S5      nU R                  U-  nU R                  U-  nU R                  5        Vs/ s H  oUR	                  U5      PM     nnU(       d*  [
        R                  " SSSS5      R                  U5      / 4$ [        U Vs/ s H  owR                  PM     snU R                  U R                  5      u  u  pn
[        U Vs/ s H  owR                  PM     snU R                  X@R                  5      u  pUS   R                  nX Vs/ s H  owR                  PM     snU-
  -  n[
        R                  " XXU-
  5      R                  U5      / [!        X5      Q4$ s  snf s  snf s  snf s  snf )Nr   r   )r   r   rA   r   r   r
   r!   r   r^   	intervalyr   rN   rF   r   r4   r   r   )r   r   r   r   rA   rp   r   r   rS   rT   r   r   r   r   s                 r   r   #HPacker._get_bbox_and_child_offsets  sU   **2.hhhh040I0I0KL0K1**X&0KL##Aq!Q/66s;R??1(./^^/djjJ(-$*+FDZZF+TZZiiI AY\\&1&$gg&1B67  R8??D*#h)*, 	, M
 0+ 2s   E2E7E<FrP   Nr   rP   r   r   r   r     s    	,r   r   c                   V   ^  \ rS rSrSrSSSS.U 4S jjjrS rS rSS	 jrS
 r	Sr
U =r$ )	PaddedBoxi  a  
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U ]  5         X l        U/U l        [	        SSSSSSSUSS9	U l        Ub  U R
                  R                  U5        g	g	)
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`.
r   r   r   rB   kr6   Tsquare,pad=0	r   r   r   	facecolor	edgecolormutation_scalesnapvisibleboxstyleN)rd   re   r   rh   r   patchupdate)r   childr   r   r   rj   s        r   re   PaddedBox.__init__  sa     	#BS#

 "JJk* #r   c                     U R                   UR                  S5      -  nU R                  S   R                  U5      R	                  U5      S/4$ )Nr   r   rc   )r   r   rh   r   r   )r   r   r   s      r   r   %PaddedBox._get_bbox_and_child_offsets6  sG    hh22266q!**84;;C@6(KKr   c                 J   U R                  U5      u  p#U R                  X!5      u  pE[        U R                  5       U5       H  u  nu  pxUR	                  XG-   XX-   45        M!     U R                  U5        U R                  5        H  nUR                  U5        M     SU l        g NF)r   r'   r   r   r   r   r   r   r   s	            r   r   PaddedBox.draw;  s    88B0t88:GDKAxLL"'27+, E 	!**,AFF8 - 
r   c                     U R                   R                  UR                  5        U(       a  U R                   R                  U5        SU l        g NT)r   
set_boundsboundsset_mutation_scaler   r   r   fontsizes      r   update_framePaddedBox.update_frameI  s4    

dkk*JJ))(3
r   c                 z    U R                  U R                  U5      5        U R                  R                  U5        g r   )r   r   r   r   r   s     r   r   PaddedBox.draw_frameO  s+    $00:;

!r   )rh   r   r   r   )r   r   )r   r   r   r   r   re   r   r   r   r   r   r   r   s   @r   r   r     s5    6+Et + +:L
" "r   r   c                      ^  \ rS rSrSrSU 4S jjr\S 5       r\R                  S 5       rS r	S r
S rS	 rS
 rS rS rSrU =r$ )DrawingAreaiU  z
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.
c                    > [         TU ]  5         Xl        X l        X0l        X@l        XPl        [        R                  " 5       U l	        [        R                  " 5       U l
        g)z
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)rd   re   r   r   r   r   _clip_childrenmtransformsAffine2Doffset_transformdpi_transform)r   r   r   r   r   cliprj   s         r   re   DrawingArea.__init__]  sL     	
  " + 4 4 6(113r   c                     U R                   $ )zT
If the children of this DrawingArea should be clipped
by DrawingArea bounding box.
)r  r   s    r   clip_childrenDrawingArea.clip_childrenq  s     """r   c                 2    [        U5      U l        SU l        g r   )boolr  r   )r   vals     r   r
  r  y  s    "3i
r   c                 4    U R                   U R                  -   $ )zH
Return the `~matplotlib.transforms.Transform` applied to the children.
)r  r  r   s    r   get_transformDrawingArea.get_transform~  s     !!D$9$999r   c                     gz
set_transform is ignored.
NrP   r   ts     r   set_transformDrawingArea.set_transform      r   c                     Xl         U R                  R                  5         U R                  R                  US   US   5        SU l        gz
Set the offset of the container.

Parameters
----------
xy : (float, float)
    The (x, y) coordinates of the offset in display units.
r   r6   TNri   r  clear	translater   r   s     r   r   DrawingArea.set_offset  @     ##%''1r!u5
r   c                     U R                   $ zReturn offset of the container.ri   r   s    r   r'   DrawingArea.get_offset      ||r   c                     UR                  S5      n[        R                  " U R                  * U-  U R                  * U-  U R
                  U-  U R                  U-  5      $ )Nr   )r   r
   r!   r   r   r   r   )r   r   dpi_cors      r   r   DrawingArea.get_bbox  sW    ++B/]]NW$t}}nw&>JJ $++"79 	9r   c                 &   U R                   R                  U5        UR                  5       (       d  UR                  U R	                  5       5        U R
                  b  U R
                  Ul        U R                  SS9nUb  UR                  U5        gg)&Add an `.Artist` to the container box.NFr   )rh   appendis_transform_setr  r  ru   r   rm   )r   r}   ro   s      r   
add_artistDrawingArea.add_artist  ss    a !!##OOD..0199 YYAFoo5o)?LL r   c           	      l   UR                  S5      nU R                  R                  5         U R                  R                  U5        [        R
                  " [        R                  " SS/SU R                  /U R                  U R                  /U R                  S//5      U R                  5       5      nU R                   HX  nU R                  (       a3  UR                  (       d"  UR                  (       d  UR                  U5        UR!                  U5        MZ     [#        XS[%        SS9S9  SU l        g )Nr   r   Fr   r   r   )r   r  r  scaler  TransformedPathmpathPathr   r   r  rh   r  clipbox	_clippathset_clip_pathr   r/   r   r   )r   r   r&  tpathrp   s        r   r   DrawingArea.draw  s     ++B/  "  )
 ++JJADKK 0T[[1Q) *  	"
 A""AII&FF8  
 	T%t|D
r   )	r  ri   r  r   r  r   r   r   r   )r   r   F)r   r   r   r   r   re   propertyr
  r   r  r  r   r'   r   r,  r   r   r   r   s   @r   r   r   U  sc    4( # #  :
9	 r   r   c                   l   ^  \ rS rSrSr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U =r$ )TextAreai  z
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)	textpropsmultilinebaselinec                d  > Uc  0 n[         R                  " SSU40 UD6U l        [        TU ]  5         U R                  /U l        [        R                  " 5       U l        [        R                  " 5       U l	        U R                  R                  U R                  U R                  -   5        X0l        g)ac  
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   )mtextText_textrd   re   rh   r  r  r  _baseline_transformr  _multilinebaseline)r   sr;  r<  rj   s       r   re   TextArea.__init__  s    " IZZ1a595
** + 4 4 6#.#7#7#9 

  !6!6!%!9!9": 	;"3r   c                 H    U R                   R                  U5        SU l        g)z&Set the text of this area as a string.TN)r@  set_textr   r   rC  s     r   rF  TextArea.set_text  s    

A
r   c                 6    U R                   R                  5       $ )z5Return the string representation of this area's text.)r@  get_textr   s    r   rJ  TextArea.get_text  s    zz""$$r   c                     Xl         SU l        g)a(  
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)rB  r   r  s     r   set_multilinebaselineTextArea.set_multilinebaseline  s     #$
r   c                     U R                   $ )z
Get multilinebaseline.
)rB  r   s    r   get_multilinebaselineTextArea.get_multilinebaseline  s     &&&r   c                     gr  rP   r  s     r   r  TextArea.set_transform  r  r   c                     Xl         U R                  R                  5         U R                  R                  US   US   5        SU l        gr  r  r   s     r   r   TextArea.set_offset
  r  r   c                     U R                   $ r!  r"  r   s    r   r'   TextArea.get_offset  r$  r   c                 d   UR                  SU R                  R                  U R                  R                  5       (       a  SOSS9u  p#nU R                  R	                  U5      u  pVnUR
                  u  pU R                  R                  5         [        U5      S:  a?  U R                  (       a.  SU	-  SX4-
  -  -
  n
U R                  R                  SXz-
  5        U
nO[        X4-
  X-
  5      nX-   n	U R                  R                  5       nSU* S-  U* S	.U   n[        R                  " X* X5      $ )
NlpTeXF)ismathr6   rZ   r      )rI   rM   rK   )get_text_width_height_descentr@  _fontproperties
get_usetex_get_layoutsizerA  r  r:   rB  r  r<   get_horizontalalignmentr
   r!   )r   r   _h_d_r   infoydrB   hyd_newh_dhar   s                 r   r   TextArea.get_bbox  s   ::$**,, JJ11335 ; @	r //9Byy  &&(t9q=T441Wsbg.F$$..q"+>Bbgqv&CAZZ//1A26QB7;C..r   c           	      l    U R                   R                  U5        [        XS[        SS9S9  SU l        g NFr   r   r   )r@  r   r/   r   r   r   s     r   r   TextArea.draw3  s)    

!T%t|D
r   )rA  rh   rB  ri   r@  r  r   )r   r   r   r   r   re   rF  rJ  rM  rP  r  r   r'   r   r   r   r   r   s   @r   r:  r:    sL      #(4 48
%
'
/. r   r:  c                   V   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rSrU =r$ )AuxTransformBoxi:  a.  
Offset Box with the aux_transform. Its children will be
transformed with the aux_transform first then will be
offsetted. The absolute coordinate of the aux_transform is meaning
as it will be automatically adjust so that the left-lower corner
of the bounding box of children will be set to (0, 0) before the
offset transform.

It is similar to drawing area, except that the extent of the box
is not predetermined but calculated from the window extent of its
children. Furthermore, the extent of the children will be
calculated in the transformed coordinate.
c                    > Xl         [        TU ]	  5         [        R                  " 5       U l        [        R                  " 5       U l        g r   )aux_transformrd   re   r  r  r  ref_offset_transform)r   rs  rj   s     r   re   AuxTransformBox.__init__H  s8    * + 4 4 6 %0$8$8$:!r   c                     U R                   R                  U5        UR                  U R                  5       5        SU l        g)r)  TN)rh   r*  r  r  r   )r   r}   s     r   r,  AuxTransformBox.add_artistP  s0    a 	**,-
r   c                 N    U R                   U R                  -   U R                  -   $ )zN
Return the :class:`~matplotlib.transforms.Transform` applied
to the children
)rs  rt  r  r   s    r   r  AuxTransformBox.get_transformV  s.    
 ""++,''( 	)r   c                     gr  rP   r  s     r   r  AuxTransformBox.set_transform_  r  r   c                     Xl         U R                  R                  5         U R                  R                  US   US   5        SU l        gr  r  r   s     r   r   AuxTransformBox.set_offsetd  r  r   c                     U R                   $ r!  r"  r   s    r   r'   AuxTransformBox.get_offsetr  r$  r   c                    U R                   R                  5       nU R                  R                  5         U R                   R                  5         U R                   Vs/ s H  o3R                  U5      PM     nn[        R                  " U5      nU R                  R                  UR                  * UR                  * 5        U R                   R                  U5        [        R                  " SSUR                  UR                  5      $ s  snf Nr   )r  
get_matrixrt  r  rh   r   r
   unionr  r   rS   
set_matrixr!   r   r   )r   r   _offrp   r   ubs         r   r   AuxTransformBox.get_bboxv  s    $$//1!!'')##%9=HA%%h/HZZ!!++RUUFRUUF;((.1bhh		:: Is   D	c           	      ~    U R                    H  nUR                  U5        M     [        XS[        SS9S9  SU l        g rn  )rh   r   r/   r   r   )r   r   rp   s      r   r   AuxTransformBox.draw  s3    AFF8  T%t|D
r   )ri   rs  r  rt  r   )r   r   r   r   r   re   r,  r  r  r   r'   r   r   r   r   r   s   @r   rq  rq  :  s5    ;)
; r   rq  c                      ^  \ rS rSrSrSrSSSSSSS	S
SSS.
r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S jr\S 5       rSS jrS rSrU =r$ )AnchoredOffsetboxi  a  
An offset box 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*.
   r6   r\                 	   
   )
zupper rightz
upper leftz
lower leftzlower rightrK   zcenter leftzcenter rightzlower centerzupper centerrM   皙?rZ   NT)r   	borderpadr   propframeonbbox_to_anchorbbox_transformc                \  > [         T
U ]  " S0 U	D6  U R                  Xx5        U R                  U5        [	        U[
        5      (       a  [        R                  " U R                  US9nXl	        X0l
        X l        Uc   [        [        R                  S   S9U l        Ob[        R                   " U5      U l        [	        U["        5      (       a2  SU;  a,  U R                  R%                  [        R                  S   5        ['        SSSSS	U R                  R)                  5       S
USS9	U l        g)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.
)locNlegend.fontsizera  ra  r   r   rB   r   Tr   r   rP   )rd   re   set_bbox_to_anchor	set_childr   strr   check_getitemcodesr  r  r   r   mplrcParamsr  	_from_anyr   set_sizer   get_size_in_pointsr   )r   r  r   r  r   r  r  r  r  r#   rj   s             r   re   AnchoredOffsetbox.__init__  s    L 	"6"?uc3$$TZZS9C"<&CLL9J,KLDI&006DI$%%&*<		""3<<0A#BC#BS99779#

r   c                 F    Xl         Ub  U R                  Ul        SU l        g)zSet the child to be anchored.NT)_childru   r   )r   r   s     r   r  AnchoredOffsetbox.set_child  s    EJ
r   c                     U R                   $ )zReturn the child.r  r   s    r   	get_childAnchoredOffsetbox.get_child  s    {{r   c                     U R                   /$ )zReturn the list of children.r  r   s    r   rn   AnchoredOffsetbox.get_children  s    }r   c                     UR                  U R                  R                  5       5      nU R                  U-  nU R	                  5       R                  U5      R                  U5      $ r   )r   r  r  r   r  r   r   )r   r   r   r   s       r   r   AnchoredOffsetbox.get_bbox  sP    ,,TYY-I-I-KLhh!~~((299#>>r   c                     U R                   c  U R                  R                  $ U R                  nUc  U R                   $ [	        U R                   U5      $ )z,Return the bbox that the box is anchored to.)_bbox_to_anchorru   r   _bbox_to_anchor_transformr   )r   	transforms     r   get_bbox_to_anchor$AnchoredOffsetbox.get_bbox_to_anchor  sL    '99>>!66I +++&t';';YGGr   c                 
   Ub  [        U[        5      (       a  Xl        O6 [        U5      nUS:X  a  US   US   SS/n[        R                  " U6 U l        X l        SU l	        g! [         a  n[        SU 35      UeSnAff = f)a  
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.
NzInvalid bbox: r\  r   r6   T)
r   r   r  r:   r   r=   r
   r!   r  r   )r   r   r  lerrs        r   r  $AnchoredOffsetbox.set_bbox_to_anchor  s     <:dH55#' CI AvQa!Q/#'#3#3T#:D )2&
  C >$!89sBCs   A$ $
B.A==Bc           	      N   U R                   UR                  U R                  R                  5       5      -  nU R	                  5       n[        U R                  [        R                  " SSUR                  UR                  5      XC5      u  pVXQR                  -
  XaR                  -
  4$ r  )r  r   r  r  r  _get_anchored_bboxr  r
   r!   r   r   r   rS   )r   r   r   r   r  r   rS   s          r   r'   AnchoredOffsetbox.get_offset  s     ~~**499+G+G+IJK002#HHd&&q!TZZE! GG|R''\))r   c                     U R                   R                  UR                  5        U(       a  U R                   R                  U5        g g r   )r   r   r   r   r   s      r   r   AnchoredOffsetbox.update_frame*  s2    

dkk*JJ))(3 r   c                    U R                  5       (       d  g U R                  U5      nUR                  U R                  R	                  5       5      nU R                  X#5        U R                  R                  U5        U R                  U R                  U5      U5      u  pEU R                  5       R                  XE45        U R                  5       R                  U5        SU l        g r   )r   r   r   r  r  r   r   r   r'   r   r  r   r   )r   r   r   r   r   r   s         r   r   AnchoredOffsetbox.draw/  s    !! %%h/,,TYY-I-I-KL$)

!x!8(C##RH-h'
r   )	r  r  r  r  r  r   r   r  r   r   )r   r   r   r   r   zorderr  re   r  r  rn   r   r  r  r+   r'   r   r   r   r   r   s   @r   r  r    s     F 
E C$ $ $	@
 @
D?	H2 * *4
 r   r  c                 f    / SQU    nUR                  U* 5      nUR                  XES9R                  $ )zq
Return the (x, y) position of the *bbox* anchored at the *parentbbox* with
the *loc* code with the *borderpad*.
)NNENWSWSEEWr  SNC)	container)r   anchoredp0)r  r   
parentbboxr  rp   r  s         r   r  r  @  s8     	ESIA!!9*-I===0333r   c                   8   ^  \ rS rSrSrSSSS.U 4S jjrSrU =r$ )	AnchoredTextiL  z
AnchoredOffsetbox with Text.
r  rZ   N)r   r  r  c                   > Uc  0 nSS1nU[        U5      -  (       a  [        S5      e[        XS9U l        U R                  R                  R                  5       n[        T	U ]  " U4X4U R                  US.UD6  g)a  
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`.
Nvaverticalalignmentz<Mixing verticalalignment with AnchoredText is not supported.)r;  )r   r  r   r  )setr=   r:  txtr@  get_fontpropertiesrd   re   )
r   rC  r  r   r  r  r#   	badkwargsfprj   s
            r   re   AnchoredText.__init__Q  s    0 <D./	s4y NP P A.XX^^..0	TXXB		r   )r  )r   r   r   r   r   re   r   r   r   s   @r   r  r  L  s     '*St # #r   r  c            
       p   ^  \ 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U =r$ )OffsetImageiw  r6   NTg      @F)	zoomcmapnorminterpolationorigin
filternorm	filterradresampler&  c       	            > [         TU ]  5         Xl        [        SU R                  UUUUUUU	S.UD6U l        U R
                  /U l        U R                  U5        U R                  U5        g )N)r   r  r  r  r  r  r  r  rP   )	rd   re   _dpi_corr   r   imagerh   set_zoomset_data)r   arrr  r  r  r  r  r  r  r  r&  r#   rj   s               r   re   OffsetImage.__init__y  st     	 	!D$:$:$($(-:&,*4)2(0	! "(	!
 **dcr   c                     [         R                  " U5      U l        U R                  R	                  U R                  5        SU l        g r   )r8   asarray_datar  r  r   )r   r  s     r   r  OffsetImage.set_data  s.    ZZ_


DJJ'
r   c                     U R                   $ r   )r  r   s    r   get_dataOffsetImage.get_data      zzr   c                     Xl         SU l        g r   )_zoomr   )r   r  s     r   r  OffsetImage.set_zoom  s    

r   c                     U R                   $ r   )r  r   s    r   get_zoomOffsetImage.get_zoom  r  r   c                     U R                   $ r!  r"  r   s    r   r'   OffsetImage.get_offset  r$  r   c                     U R                   /$ r   )r  r   s    r   rn   OffsetImage.get_children  s    

|r   c                     U R                   (       a  UR                  S5      OSnU R                  5       nU R                  5       nUR                  S S u  pVX&-  U-  X%-  U-  p[
        R                  " SSXx5      $ )Nr   r\  r   )r  r   r  r  shaper
   r!   )	r   r   r&  r  datanynxrB   rh  s	            r   r   OffsetImage.get_bbox  sk    37==(++B/b}}}}BQ|d"GL4$711a++r   c                 H    U R                   R                  U5        SU l        g r   )r  r   r   r   s     r   r   OffsetImage.draw  s    

!
r   )rh   r  r  r  r  r   )r   r   r   r   re   r  r  r  r  r'   rn   r   r   r   r   r   s   @r   r  r  w  sX     #  @
, r   r  c            
          \ rS rSrSrSrS r\R                  SSSSSSSSS	.S
 jj5       r	\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       rS rS rS rSS jrS rSS jrSS jrS rS rSrg)AnnotationBboxi  z
Container for an `OffsetBox` referring to a specific position *xy*.

Optionally an arrow pointing from the offsetbox to *xy* can be drawn.

This is like `.Annotation`, but with `OffsetBox` instead of `.Text`.
r  c                 L    SU R                   S   S SU R                   S   S S3$ )NzAnnotationBbox(r   g,r6   ))r   r   s    r   __str__AnnotationBbox.__str__  s+     Aa
1~Q??r   NTr  rZ   rZ   )r  r   annotation_clipbox_alignment	bboxprops
arrowpropsr   c                   [         R                  R                  U 5        [        R                  R                  XXHS9  Xl        Ub  UR                  5       OSU l        U R                  U5        Ub  UOUU l	        Ub  UOUU l
        Xl        Ub<  U R                  R                  SS5      U l        [        S0 U R                  D6U l        OSU l        SU l        [!        SSSSSU R"                  R%                  5       S	US
9U l        U R&                  R)                  SUS9  U
(       a  U R&                  R*                  " S0 U
D6  U R-                  U5        g)az	  
Parameters
----------
offsetbox : `OffsetBox`

xy : (float, float)
    The point *(x, y)* to annotate. The coordinate system is determined
    by *xycoords*.

xybox : (float, float), default: *xy*
    The position *(x, y)* to place the text at. The coordinate system
    is determined by *boxcoords*.

xycoords : single or two-tuple of str or `.Artist` or `.Transform` or callable, default: 'data'
    The coordinate system that *xy* is given in. See the parameter
    *xycoords* in `.Annotation` for a detailed description.

boxcoords : single or two-tuple of str or `.Artist` or `.Transform` or callable, default: value of *xycoords*
    The coordinate system that *xybox* is given in. See the parameter
    *textcoords* in `.Annotation` for a detailed description.

frameon : bool, default: True
    By default, the text is surrounded by a white `.FancyBboxPatch`
    (accessible as the ``patch`` attribute of the `.AnnotationBbox`).
    If *frameon* is set to False, this patch is made invisible.

annotation_clip: bool or None, default: None
    Whether to clip (i.e. not draw) the annotation when the annotation
    point *xy* is outside the Axes area.

    - If *True*, the annotation will be clipped when *xy* is outside
      the Axes.
    - If *False*, the annotation will always be drawn.
    - If *None*, the annotation will be clipped when *xy* is outside
      the Axes and *xycoords* is 'data'.

pad : float, default: 0.4
    Padding around the offsetbox.

box_alignment : (float, float)
    A tuple of two floats for a vertical and horizontal alignment of
    the offset box w.r.t. the *boxcoords*.
    The lower-left corner is (0, 0) and upper-right corner is (1, 1).

bboxprops : dict, optional
    A dictionary of properties to set for the annotation bounding box,
    for example *boxstyle* and *alpha*.  See `.FancyBboxPatch` for
    details.

arrowprops: dict, optional
    Arrow properties, see `.Annotation` for description.

fontsize: float or str, optional
    Translated to points and passed as *mutation_scale* into
    `.FancyBboxPatch` to scale attributes of the box style (e.g. pad
    or rounding_size).  The name is chosen in analogy to `.Text` where
    *fontsize* defines the mutation scale as well.  If not given,
    :rc:`legend.fontsize` is used.  See `.Text.set_fontsize` for valid
    values.

**kwargs
    Other `AnnotationBbox` properties.  See `.AnnotationBbox.set` for
    a list.
)xycoordsr  Nrelposr  r   r   rB   r   T)r   r   r   r   r   r   r   r   squarer   )rc   )r6   r6   rP   )rs   rt   re   r>  _AnnotationBase	offsetboxcopyr  set_fontsizexybox	boxcoords_box_alignmentpop_arrow_relposr   arrow_patchr   r  r  r   set_boxstyler  rf   )r   r  r   r  r  r   r  r   r  r  r  r  r   r#   s                 r   re   AnnotationBbox.__init__  s9   X 	%&&x 	' 	J #/9/E*//+4(##/UR
&/&;+!!%!4!4Xz!JD.  B15 BD "&D#D#BS99779

 	

c2JJNN'Y'f%r   c                     U R                   $ r   )r  r   s    r   xyannAnnotationBbox.xyann8  s    zzr   c                     Xl         SU l        g r   )r  r   )r   r(  s     r   r(  r)  <  s    

r   c                     U R                   $ r   )r   r   s    r   	anncoordsAnnotationBbox.anncoordsA  r   r   c                     Xl         SU l        g r   )r   r   )r   coordss     r   r,  r-  E  s    
r   c                     U R                  U5      (       a  S0 4$ U R                  S 5      (       d  S0 4$ U R                  R                  U5      $ r   )rz   	_check_xyr  r{   )r   r|   s     r   r{   AnnotationBbox.containsJ  sK    !!*--"9~~d##"9~~&&z22r   c                     U R                   U R                  /nU R                  (       a  UR                  U R                  5        U$ r   )r  r   r$  r*  )r   r   s     r   rn   AnnotationBbox.get_childrenR  s4    NNDJJ/OOD,,-r   c                     U R                   b  U R                   R                  U5        U R                  R                  U5        [        R                  R                  X5        g r   )r$  rm   r  rs   rt   )r   ro   s     r   rm   AnnotationBbox.set_figureX  sF    ''',!!#&!!$,r   c                 Z    Uc  [         R                  S   n[        US9U l        SU l        g)zS
Set the fontsize in points.

If *s* is not given, reset to :rc:`legend.fontsize`.
Nr  r  T)r  r  r   r  r   rG  s     r   r  AnnotationBbox.set_fontsize^  s+     9./A"*	
r   c                 6    U R                   R                  5       $ )zReturn the fontsize in points.)r  r  r   s    r   get_fontsizeAnnotationBbox.get_fontsizej  s    yy++--r   c                     Uc  U R                  SS9R                  5       nU R                  U5        [        R                  " U R                  5        Vs/ s H  nUR                  U5      PM     sn5      $ s  snf r   )r   r   update_positionsr
   r  rn   r   r   r   r   s      r   r    AnnotationBbox.get_window_extentn  st    D1??AHh'zz(,(9(9(;=(;u !228<(;= > 	> =   A6c                     Uc  U R                  SS9R                  5       nU R                  U5        [        R                  " U R                  5        Vs/ s H  nUR                  U5      PM     sn5      $ s  snf r   )r   r   r=  r
   r  rn   get_tightbboxr>  s      r   rB  AnnotationBbox.get_tightbboxv  st    D1??AHh'zz(,(9(9(;=(;u !..x8(;= > 	> =r@  c                     U R                  XR                  U R                  5      u  p#U R                  R	                  U5      nU R
                  u  pVU R                  R                  X%UR                  -  -
  UR                  -
  X6UR                  -  -
  UR                  -
  45        U R                  R                  U5      nU R                  R                  UR                  5        UR                  U R!                  5       5      nU R                  R#                  U5        U R$                  (       a  UR&                  UR(                  U R*                  -  -   nU R-                  U5      n	U R.                  R1                  X5        SU R$                  ;   a  UR                  U R$                  S   5      nU R.                  R#                  U5        U R$                  R3                  SU R                  5      n
U R.                  R5                  U
5        gg)zHUpdate pixel positions for the annotated point, the text, and the arrow.r   patchAN)_get_xyr  r   r  r   r!  r   r   r   r   rS   r   r   r   r   r   r:  r   r  r  ra  r#  _get_position_xyr$  set_positionsget
set_patchA)r   r   ox0oy0r   fwfhr   arrow_begin	arrow_endrE  s              r   r=  AnnotationBbox.update_positions~  s    <<**dnnE~~&&x0$$!!djj= 477*CT[[.,@477,JK	M ~~//9

dkk*!2243D3D3FG

%%n5??
 ''DII0B0B$BBK--h7I **;B4??2!)!:!:OO$45"7 //?__((4::>F''/' r   c                    U R                  5       (       a  U R                  U5      (       d  g UR                  U R                  R                  U R                  5       S9  U R                  U5        U R                  bb  U R                  R                  SS9c-  U R                  SS9=nb  U R                  R                  U5        U R                  R                  U5        U R                  R                  U5        U R                  R                  U5        UR                  U R                  R                  5        SU l        g )N)gidFr   )r   r1  
open_grouprj   r   get_gidr=  r$  r   rm   r   r   r  close_groupr   )r   r   ro   s      r   r   AnnotationBbox.draw  s    !!)A)ADNN33Hh''  +++7? OOO77SD  ++C0!!(+

!H%T^^445
r   )
r#  r!  r$  r  r   r  r   r  r   r  )Nr  Nr   )r   r   r   r   r   r  r  r   interpdre   r8  r(  r   r,  r{   rn   rm   r  r:  r   rB  r=  r   r   rP   r   r   r  r    s     F@ i&3!%) i& i&V   \\     3-
.>>"0Hr   r  c                   v    \ rS rSrSrSS jr\" S 5      r\" S 5      rS r	S r
S rS	 rS
 rS rS rS rSrg)DraggableBasei  aG  
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                    Xl         UR                  5       (       d  UR                  S5        SU l        U=(       a    U R                  R
                  U l        U R                  R                  nSU R                  4SU R                  4SU R                  44 VVs/ s H5  u  pE[        R                  " UR                  UR                  XE5      5      PM7     snnU l        g s  snnf )NTF
pick_eventbutton_release_eventmotion_notify_event)
ref_artistpickable
set_picker
got_artistcanvassupports_blit	_use_blit	callbackson_pick
on_release	on_motionr)   partial
disconnect_connect_picklable_disconnectors)r   r_  use_blitrf  namefuncs         r   re   DraggableBase.__init__  s    $""$$!!$'!?dkk&?&?KK))	
 t||,'9&7

 $$i&B&B4&NP
 
s   <C c                 H    U R                   R                  SS9R                  $ r   )r_  r   rc  r   s    r   r   DraggableBase.<lambda>  s    4??#=#=4#=#H#O#Or   c                 d    U R                   S S  Vs/ s H  oR                  S   PM     sn$ s  snf )Nr\  r   )rm  r"   )r   rk  s     r   r   rs    s6    -1-@-@!-D"F-Dz-D"F "Fs   -c                 2   U R                  5       (       Ga  U R                  (       a  UR                  U R                  -
  nUR                  U R
                  -
  nU R                  X#5        U R                  (       a  U R                  R                  U R                  5        U R                  R                  U R                  R                  SS9R                  5       5        U R                  R                  5         g U R                  R                  5         g g g r   )_check_still_parentedrb  xmouse_xymouse_yupdate_offsetre  rc  restore_region
backgroundr_  r   r   r   blit)r   evtdxdys       r   ri  DraggableBase.on_motion  s    %%''DOO%B%Br&~~**4??;$$OO..D.9GGIK  "  " -<'r   c                    U R                  5       (       GaG  UR                  U R                  :X  aM  UR                  R                  U l        UR                  R                  U l        U R                  5         SU l	        U R                  (       a  U R                  (       a  U R                  R                  S5        U R                  R                  5         U R                  R                  SS9nU R                  R                  UR                   5      U l        U R                  R                  UR%                  5       5        U R                  R'                  5         g g g g )NTFr   )rv  artistr_  r|   rw  rx  ry  rz  save_offsetrb  re  set_animatedrc  r   r   copy_from_bboxr   r}  r   r~  )r   r  ro   s      r   rg  DraggableBase.on_pick  s    %%''zzT__,"~~//"~~//  ""&4>>,,T2  "oo00e0<"&++"<"<SXX"F$$S%6%6%89  " $2 (r   c                    U R                  5       (       a  U R                  (       a  U R                  5         SU l        U R                  (       a  U R                  R                  U R                  5        U R                  R                  U R                  R                  R                  5       5        U R                  R                  5         U R                  R                  S5        g g g g r   )rv  rb  finalize_offsetre  rc  r|  r}  r_  r   figurer   r~  r  )r   events     r   rh  DraggableBase.on_release  s    %%''DOO  "#DO~~**4??;$$T__%;%;%I%I%KL  ",,U3	  -<'r   c                 Z    U R                   R                  SS9c  U R                  5         gg)NFr   T)r_  r   rk  r   s    r   rv  #DraggableBase._check_still_parented  s*    ??%%5%19OOr   c                 8    U R                    H
  nU" 5         M     g)zDisconnect the callbacks.N)rm  )r   disconnectors     r   rk  DraggableBase.disconnect  s     //LN 0r   c                     g r   rP   r   s    r   r  DraggableBase.save_offset      r   c                     g r   rP   )r   r  r  s      r   r{  DraggableBase.update_offset  r  r   c                     g r   rP   r   s    r   r  DraggableBase.finalize_offset  r  r   )rm  re  r}  rb  rx  rz  r_  NF)r   r   r   r   r   re   r8  rc  cidsri  rg  rh  rv  rk  r  r{  r  r   rP   r   r   rZ  rZ    sR    8
$ OPF F GD##4
r   rZ  c                   >   ^  \ rS rSrSU 4S jjrS rS rS rSrU =r	$ )DraggableOffsetBoxi"  c                 ,   > [         TU ]  XS9  X l        g N)rn  )rd   re   r  )r   r_  r  rn  rj   s       r   re   DraggableOffsetBox.__init__#  s    7"r   c                     U R                   nUR                  SS9R                  5       nUR                  UR	                  U5      U5      nUu  U l        U l        U R                   R                  U5        g r   )r  r   r   r'   r   offsetbox_xoffsetbox_yr   )r   r  r   offsets       r   r  DraggableOffsetBox.save_offset'  sf    NN	''T'2@@B%%i&8&8&BHM-3*$*!!&)r   c                 v    U R                   U-   U R                  U-   4nU R                  R                  U5        g r   )r  r  r  r   )r   r  r  loc_in_canvass       r   r{   DraggableOffsetBox.update_offset.  s4    ((2-t/?/?"/DD!!-0r   c                     U R                   nUR                  SS9R                  5       nUR                  U5      nUR                  u  pEXCR
                  -   XSR                  -   4nU$ r   )r  r   r   r   ri   r   rS   )r   r  r   r   r   r   r  s          r   get_loc_in_canvas$DraggableOffsetBox.get_loc_in_canvas2  s`    NN	''T'2@@B!!(+""ggrGG|4r   )r  r  r  r  )
r   r   r   r   re   r  r{  r  r   r   r   s   @r   r  r  "  s    #*1 r   r  c                   8   ^  \ rS rSrSU 4S jjrS rS rSrU =r$ )DraggableAnnotationi;  c                 ,   > [         TU ]  XS9  Xl        g r  )rd   re   
annotation)r   r  rn  rj   s      r   re   DraggableAnnotation.__init__<  s    7$r   c                     U R                   nUR                  5       R                  UR                  5      u  U l        U l        g r   )r  r  r  r(  r   r   )r   anns     r   r  DraggableAnnotation.save_offset@  s1    oo,,.88Cr   c                     U R                   nUR                  5       R                  5       R                  U R                  U-   U R
                  U-   45      Ul        g r   )r  r  invertedr  r   r   r(  )r   r  r  r  s       r   r{  !DraggableAnnotation.update_offsetD  sG    oo%%'002<<WWr\477R<(*	r   )r  r   r   r  )	r   r   r   r   re   r  r{  r   r   r   s   @r   r  r  ;  s    %D* *r   r  )r1   )rH   )7r   r)   numpyr8   
matplotlibr  r   r   matplotlib.artistr  rs   matplotlib.pathpathr1  matplotlib.texttextr>  matplotlib.transforms
transformsr  matplotlib.font_managerr   matplotlib.imager   matplotlib.patchesr   r   r	   r.   r
   r   r   r-   r+   r/   rF   r^   rt   r`   r   r   r   r   r   r:  rq  r  r  r  r  r  r  rZ  r  r  rP   r   r   <module>r     sA  0    ' #   + 2 &B B A A 	(&
Nb0fw wt," ,"^%(j %(P,j ,DU"	 U"pm) m`ry rjOi Odq	 qh	4($ (VD) DNrW^^U%:%: rjl l^ 2*- *r   