
    h                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	J
r
JrJrJ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JrJrJrJr  SS	KJrJrJ r J!r!J"r"J#r#  SS
K$J%r%  SSK&J'r'J(r(J)r)  SSK&J*r*J+r+  SSK,J-r-J.r.J/r/J0r0J1r1J2r2  SSK3J4r4J5r5J6r6  SSK7J8r8   " S S\.5      r9Sr:Sr;Sr<\;R{                  SS\<SS9\:-   r>\
R~                  R                  \>S9  SrA\;R{                  SSS\AS9\:-   rB\
R~                  R                  \BS9  \;R{                  SS \<\AS9\:-   rC\
R~                  R                  \CS!9  \;R{                  SS \<\AS9rD\
R~                  R                  \DS"9   " S# S$\5      rES)S% jrFS)S& jrGSSS'.S( jrHg)*aT  
The legend module defines the Legend class, which is responsible for
drawing legends associated with Axes and/or figures.

.. important::

    It is unlikely that you would ever create a Legend instance manually.
    Most users would normally create a legend via the `~.Axes.legend`
    function. For more details on legends there is also a :ref:`legend guide
    <legend_guide>`.

The `Legend` class is a container of legend handles and legend texts.

The legend handler map specifies how to create legend handles from artists
(lines, patches, etc.) in the Axes or figures. Default legend handlers are
defined in the :mod:`~matplotlib.legend_handler` module. While not all artist
types are covered by the default legend handlers, custom legend handlers can be
defined to support arbitrary objects.

See the :ref`<legend_guide>` for more
information.
    N)_api
_docstringcbookcolors	offsetbox)Artistallow_rasterization)silent_list)FontProperties)Line2D)Patch	RectangleShadowFancyBboxPatch	StepPatch)
CollectionCircleCollectionLineCollectionPathCollectionPolyCollectionRegularPolyCollection)Text)BboxBboxBaseTransformedBbox)BboxTransformToBboxTransformFrom)AnchoredOffsetboxDraggableOffsetBoxHPackerVPackerDrawingAreaTextArea)ErrorbarContainerBarContainerStemContainer   )legend_handlerc                   >   ^  \ rS rSrSU 4S jjrS rS rS rSrU =r	$ )DraggableLegend6   c                 |   > Xl         [        R                  " SS/US9  X0l        [        TU ]  XR                  US9  g)a  
Wrapper around a `.Legend` to support mouse dragging.

Parameters
----------
legend : `.Legend`
    The `.Legend` instance to wrap.
use_blit : bool, optional
    Use blitting for faster image composition. For details see
    :ref:`func-animation`.
update : {'loc', 'bbox'}, optional
    If "loc", update the *loc* parameter of the legend upon finalizing.
    If "bbox", update the *bbox_to_anchor* parameter.
locbboxupdate)use_blitN)legendr   check_in_list_updatesuper__init___legend_box)selfr2   r1   r0   	__class__s       C/var/www/html/env/lib/python3.13/site-packages/matplotlib/legend.pyr6   DraggableLegend.__init__7   s;     E6?6:!3!3hG    c                     U R                   S:X  a   U R                  U R                  5       5        g U R                   S:X  a   U R                  U R                  5       5        g g )Nr-   r.   )r4   _update_locget_loc_in_canvas_update_bbox_to_anchorr8   s    r:   finalize_offsetDraggableLegend.finalize_offsetM   sM    <<5 T3356\\V#''(>(>(@A $r<   c                 J   U R                   R                  5       nUR                  S:X  d  UR                  S:X  a5  U R                   R	                  S 5        U R                   R                  5       n[        U5      n[        UR                  U5      5      U R                   l        g )Nr   )	r2   get_bbox_to_anchorwidthheightset_bbox_to_anchorr   tuple	transform_loc)r8   loc_in_canvasr.   _bbox_transforms       r:   r>   DraggableLegend._update_locS   sv    {{--/ ::?dkkQ.KK**40;;113D+D1 !:!:=!IJr<   c                     U R                   R                  R                  R                  U5      nU R                   R	                  U5        g N)r2   axes	transAxesrJ   rH   )r8   rL   loc_in_bboxs      r:   r@   &DraggableLegend._update_bbox_to_anchor]   s4    kk&&00::=I&&{3r<   )r4   r2   Fr-   )
__name__
__module____qualname____firstlineno__r6   rB   r>   r@   __static_attributes____classcell__r9   s   @r:   r*   r*   6   s    H,BK4 4r<   r*   a9  
bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
    Box that is used to position the legend in conjunction with *loc*.
    Defaults to ``axes.bbox`` (if called as a method to `.Axes.legend`) or
    ``figure.bbox`` (if ``figure.legend``).  This argument allows arbitrary
    placement of the legend.

    Bbox coordinates are interpreted in the coordinate system given by
    *bbox_transform*, with the default transform
    Axes or Figure coordinates, depending on which ``legend`` is called.

    If a 4-tuple or `.BboxBase` is given, then it specifies the bbox
    ``(x, y, width, height)`` that the legend is placed in.
    To put the legend in the best location in the bottom right
    quadrant of the Axes (or figure)::

        loc='best', bbox_to_anchor=(0.5, 0., 0.5, 0.5)

    A 2-tuple ``(x, y)`` places the corner of the legend specified by *loc* at
    x, y.  For example, to put the legend's upper right-hand corner in the
    center of the Axes (or figure) the following keywords can be used::

        loc='upper right', bbox_to_anchor=(0.5, 0.5)

ncols : int, default: 1
    The number of columns that the legend has.

    For backward compatibility, the spelling *ncol* is also supported
    but it is discouraged. If both are given, *ncols* takes precedence.

prop : None or `~matplotlib.font_manager.FontProperties` or dict
    The font properties of the legend. If None (default), the current
    :data:`matplotlib.rcParams` will be used.

fontsize : int or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
    The font size of the legend. If the value is numeric the size will be the
    absolute font size in points. String values are relative to the current
    default font size. This argument is only used if *prop* is not specified.

labelcolor : str or list, default: :rc:`legend.labelcolor`
    The color of the text in the legend. Either a valid color string
    (for example, 'red'), or a list of color strings. The labelcolor can
    also be made to match the color of the line or marker using 'linecolor',
    'markerfacecolor' (or 'mfc'), or 'markeredgecolor' (or 'mec').

    Labelcolor can be set globally using :rc:`legend.labelcolor`. If None,
    use :rc:`text.color`.

numpoints : int, default: :rc:`legend.numpoints`
    The number of marker points in the legend when creating a legend
    entry for a `.Line2D` (line).

scatterpoints : int, default: :rc:`legend.scatterpoints`
    The number of marker points in the legend when creating
    a legend entry for a `.PathCollection` (scatter plot).

scatteryoffsets : iterable of floats, default: ``[0.375, 0.5, 0.3125]``
    The vertical offset (relative to the font size) for the markers
    created for a scatter plot legend entry. 0.0 is at the base the
    legend text, and 1.0 is at the top. To draw all markers at the
    same height, set to ``[0.5]``.

markerscale : float, default: :rc:`legend.markerscale`
    The relative size of legend markers compared to the originally drawn ones.

markerfirst : bool, default: True
    If *True*, legend marker is placed to the left of the legend label.
    If *False*, legend marker is placed to the right of the legend label.

reverse : bool, default: False
    If *True*, the legend labels are displayed in reverse order from the input.
    If *False*, the legend labels are displayed in the same order as the input.

    .. versionadded:: 3.7

frameon : bool, default: :rc:`legend.frameon`
    Whether the legend should be drawn on a patch (frame).

fancybox : bool, default: :rc:`legend.fancybox`
    Whether round edges should be enabled around the `.FancyBboxPatch` which
    makes up the legend's background.

shadow : None, bool or dict, default: :rc:`legend.shadow`
    Whether to draw a shadow behind the legend.
    The shadow can be configured using `.Patch` keywords.
    Customization via :rc:`legend.shadow` is currently not supported.

framealpha : float, default: :rc:`legend.framealpha`
    The alpha transparency of the legend's background.
    If *shadow* is activated and *framealpha* is ``None``, the default value is
    ignored.

facecolor : "inherit" or color, default: :rc:`legend.facecolor`
    The legend's background color.
    If ``"inherit"``, use :rc:`axes.facecolor`.

edgecolor : "inherit" or color, default: :rc:`legend.edgecolor`
    The legend's background patch edge color.
    If ``"inherit"``, use :rc:`axes.edgecolor`.

mode : {"expand", None}
    If *mode* is set to ``"expand"`` the legend will be horizontally
    expanded to fill the Axes area (or *bbox_to_anchor* if defines
    the legend's size).

bbox_transform : None or `~matplotlib.transforms.Transform`
    The transform for the bounding box (*bbox_to_anchor*). For a value
    of ``None`` (default) the Axes'
    :data:`~matplotlib.axes.Axes.transAxes` transform will be used.

title : str or None
    The legend's title. Default is no title (``None``).

title_fontproperties : None or `~matplotlib.font_manager.FontProperties` or dict
    The font properties of the legend's title. If None (default), the
    *title_fontsize* argument will be used if present; if *title_fontsize* is
    also None, the current :rc:`legend.title_fontsize` will be used.

title_fontsize : int or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}, default: :rc:`legend.title_fontsize`
    The font size of the legend's title.
    Note: This cannot be combined with *title_fontproperties*. If you want
    to set the fontsize alongside other font properties, use the *size*
    parameter in *title_fontproperties*.

alignment : {'center', 'left', 'right'}, default: 'center'
    The alignment of the legend title and the box of entries. The entries
    are aligned as a single block, so that markers always lined up.

borderpad : float, default: :rc:`legend.borderpad`
    The fractional whitespace inside the legend border, in font-size units.

labelspacing : float, default: :rc:`legend.labelspacing`
    The vertical space between the legend entries, in font-size units.

handlelength : float, default: :rc:`legend.handlelength`
    The length of the legend handles, in font-size units.

handleheight : float, default: :rc:`legend.handleheight`
    The height of the legend handles, in font-size units.

handletextpad : float, default: :rc:`legend.handletextpad`
    The pad between the legend handle and text, in font-size units.

borderaxespad : float, default: :rc:`legend.borderaxespad`
    The pad between the Axes and legend border, in font-size units.

columnspacing : float, default: :rc:`legend.columnspacing`
    The spacing between columns, in font-size units.

handler_map : dict or None
    The custom dictionary mapping instances or types to a legend
    handler. This *handler_map* updates the default handler map
    found at `matplotlib.legend.Legend.get_legend_handler_map`.

draggable : bool, default: False
    Whether the legend can be dragged with the mouse.
a4  
loc : str or pair of floats, default: {default}
    The location of the legend.

    The strings ``'upper left'``, ``'upper right'``, ``'lower left'``,
    ``'lower right'`` place the legend at the corresponding corner of the
    {parent}.

    The strings ``'upper center'``, ``'lower center'``, ``'center left'``,
    ``'center right'`` place the legend at the center of the corresponding edge
    of the {parent}.

    The string ``'center'`` places the legend at the center of the {parent}.
{best}
    The location can also be a 2-tuple giving the coordinates of the lower-left
    corner of the legend in {parent} coordinates (in which case *bbox_to_anchor*
    will be ignored).

    For back-compatibility, ``'center right'`` (but no other location) can also
    be spelled ``'right'``, and each "string" location can also be given as a
    numeric value:

    ==================   =============
    Location String      Location Code
    ==================   =============
    'best' (Axes only)   0
    'upper right'        1
    'upper left'         2
    'lower left'         3
    'lower right'        4
    'right'              5
    'center left'        6
    'center right'       7
    'lower center'       8
    'upper center'       9
    'center'             10
    ==================   =============
    {outside}a/  
    The string ``'best'`` places the legend at the location, among the nine
    locations defined so far, with the minimum overlap with other drawn
    artists.  This option can be quite slow for plots with large amounts of
    data; your plotting speed may benefit from providing a specific location.
rQ   z:rc:`legend.loc` )parentdefaultbestoutside)_legend_kw_axesaX  
    If a figure is using the constrained layout manager, the string codes
    of the *loc* keyword argument can get better layout behaviour using the
    prefix 'outside'. There is ambiguity at the corners, so 'outside
    upper right' will make space for the legend above the rest of the
    axes in the layout, and 'outside right upper' will make space on the
    right side of the layout.  In addition to the values of *loc*
    listed above, we have 'outside right upper', 'outside right lower',
    'outside left upper', and 'outside left lower'.  See
    :ref:`legend_guide` for more details.
figurez'upper right')_legend_kw_figurezaxes/figurez3:rc:`legend.loc` for Axes, 'upper right' for Figure)_legend_kw_doc)_legend_kw_set_loc_docc            $         ^  \ rS rSrSrSS0\R                  ErSrS r\	R                  SSSSS	SSSSSSSSSSSSS
SSSSSSSSSSSSSSS
S	S."U 4S jj5       rS r\	R                  S2S j5       rS rS rS r\" \\5      rS r\S 5       r\\R0                  " 5       \\R4                  " 5       \\R8                  " 5       \\R<                  " 5       \\R@                  " 5       \!\RD                  " 5       \#\RH                  " 5       \%\RL                  " 5       \'\R<                  " \RP                  S9\)\RT                  " 5       \+\RX                  " 5       \-\R\                  " 5       0r/\0S 5       r1\0S 5       r2\0S 5       r3S r4\5S 5       r6S3S jr7S r8S r9S r:S r;S  r<S! r=S" r>S# r?S2S$ jr@S% rAS2S& jrBS2S' jrCS( rDS) rE\ErFS* rGS2S+ jrHS, rIS- rJS. rKS4S/ jrLS0 rMS1rNU =rO$ )5LegendiV  z$
Place a legend on the figure/axes.
r`   r      c                     g)Nrh    rA   s    r:   __str__Legend.__str___  s    r<   NTFr'   center)"r-   	numpointsmarkerscalemarkerfirstreversescatterpointsscatteryoffsetspropfontsize
labelcolor	borderpadlabelspacinghandlelengthhandleheighthandletextpadborderaxespadcolumnspacingncolsmodefancyboxshadowtitletitle_fontsize
framealpha	edgecolor	facecolorbbox_to_anchorbbox_transformframeonhandler_maptitle_fontproperties	alignmentncol	draggablec       "         
  > SSK Jn&  SSKJn'  [        T0U ]  5         Uc$  [        [        R                  " US5      S9U l	        Ob[        R                  " U5      U l	        [        U[        5      (       a2  SU;  a,  U R                  R                  [        R                  S   5        U R                  R                  5       U l        / U l        / U l        SU l        U!U l        [        R                  " US5      U l        [        R                  " US	5      U l        [        R                  " U	S
5      U l        [        R                  " US5      U l        [        R                  " US5      U l        [        R                  " US5      U l        [        R                  " US5      U l        [        R                  " US5      U l        [        R                  " US5      U l        [        R                  " US5      U l        [        R                  " US5      U l        U(       a  / [A        U5      Qn/ [A        U5      Qn[C        U5      S:  a  SnUS:w  a  UOU$U l"        U R*                  S::  a  [G        SU-  5      eU
c  [H        RJ                  " / SQ5      U l&        O[H        RN                  " U
5      U l&        U R.                  [C        U RL                  5      -  S-   n([H        RP                  " U RL                  U(5      SU R.                   U l&        SU l)        [        UU&5      (       a,  SU l*        Xl+        U RY                  UR[                  SS95        O5[        UU'5      (       a  SU l*        U RY                  U5        O[]        S5      eXl/        UU l0        U Rc                  UU5        SSS.U l2        [        U R>                  [        5      (       a-  U Rd                  Rg                  U R>                  5        SU l        O[U R>                  S;   a  [i        U R>                  5      U l        O0[G        SU R>                  < S[k        U R>                  5       S 35      e[        R                  " US!5      nUS":X  a  [        R                  S#   n[        R                  " US$5      nUS":X  a  [        R                  S%   n[        R                  " US&5      n[m        S'SSUUUb  UOU(       a  SO[        R                  S(   U(       a  S)OS*U R                   S[        R                  " U S+5      S,9
U l7        U Rq                  U Rn                  5        [r        Rt                  " / S-QU#S.9  U#U l;        U Ry                  X#U5        U R{                  U5        Ub  U"b  [G        S/5      e[        R                  " U"5      n)[        U"[        5      (       a+  SU";  a$  [        R                  S0   nU)R                  U5        ONUb  U)R                  U5        O9[        U"[        5      (       d$  [        R                  S0   nU)R                  U5        U R}                  UU)S19  SU l?        U R                  U%S29  S3S4/S5S4/S5S4/S6S7/S6S7/S8.n*[        R                  " US95      nUc  [        R                  S:   n[        U[        5      (       a  UU*;   a  U*U   n+[        U R$                  U R"                  5       H  u  n,n- U,R                  5       b  M   U+ H  n. [        U,U.5      " 5       n/[        U/[H        R                  5      (       aV  U/R                  S   S:X  d-  [H        R                  " U/U/S   5      R                  5       (       a  U-R                  U/S   5        OOU-R                  U/5          M     M     g[        R                  " US;5      (       a%  U R"                   H  n-U-R                  U5        M     g[H        R                  " U5      (       aZ  [        U R"                  [        R                  " [        R                  " U5      5      5       H  u  n-n/U-R                  U/5        M     g[G        S<U< 35      e! [         a     GNyf = f! [         a     GM  f = f)=a_  
Parameters
----------
parent : `~matplotlib.axes.Axes` or `.Figure`
    The artist that contains the legend.

handles : list of (`.Artist` or tuple of `.Artist`)
    A list of Artists (lines, patches) to be added to the legend.

labels : list of str
    A list of labels to show next to the artists. The length of handles
    and labels should be the same. If they are not, they are truncated
    to the length of the shorter list.

Other Parameters
----------------
%(_legend_kw_doc)s

Attributes
----------
legend_handles
    List of `.Artist` objects added as legend entries.

    .. versionadded:: 3.7
r   )Axes)
FigureBaseNzlegend.fontsize)sizer   zlegend.numpointszlegend.markerscalezlegend.scatterpointszlegend.borderpadzlegend.labelspacingzlegend.handlelengthzlegend.handleheightzlegend.handletextpadzlegend.borderaxespadzlegend.columnspacingzlegend.shadow   r'   z numpoints must be > 0; it was %d)g      ?g      ?g      ?TFrootz0Legend needs either Axes or FigureBase as parent)oxoy)r   r'   TFz*Legend shadow must be a dict or bool, not z	 of type .zlegend.facecolorinheritzaxes.facecolorzlegend.edgecolorzaxes.edgecolorzlegend.fancybox)r   r   zlegend.framealphazround,pad=0,rounding_size=0.2zsquare,pad=0zlegend.frameon)
xyrF   rG   r   r   alphaboxstylemutation_scalesnapvisiblern   leftrightr   zctitle_fontsize and title_fontproperties can't be specified at the same time. Only use one of them. zlegend.title_fontsize)ru   )state	get_colorget_facecolorget_markerfacecolorget_markeredgecolorget_edgecolor)	linecolormarkerfacecolormfcmarkeredgecolormeczlegend.labelcolorz
text.colornonezInvalid labelcolor: )Rmatplotlib.axesr   matplotlib.figurer   r5   r6   r   mpl
_val_or_rcru   	_from_any
isinstancedictset_sizercParamsget_size_in_points	_fontsizetextslegend_handles_legend_title_box_custom_handler_mapro   rp   rs   rx   ry   rz   r{   r|   r}   r~   r   reversedlen_ncols
ValueErrornparray_scatteryoffsetsasarraytiler7   isaxesrQ   
set_figure
get_figure	TypeErrorr^   _moderH   _shadow_propsr0   booltyper   legendPatch_set_artist_propsr   r3   
_alignment_init_legend_boxset_loc	set_title
_draggableset_draggablestrzip	get_arrayAttributeErrorgetattrndarrayshapeiscloseall	set_colorr   
_str_equaliterable	itertoolscycler   to_rgba_array)1r8   r^   handleslabelsr-   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   repstitle_prop_fpcolor_gettersgetter_nameshandletextgetter_namecolorr9   s1                                                   r:   r6   Legend.__init__b  s:   L 	)0<&CNN8EV,WXDI&006DI$%%&*<		""3<<0A#BC557
 !% $/ 	3EF>>+7KL ^^M;QR	3EFNN<9NONN<9NONN<9NO ^^M;QR ^^M;QR ^^M;QRnnV_=(x'(F*)*Gw<!E$zet>>Q?)KLL "$&HH-I$JD!$&JJ$?D!!!S)>)>%??!C "(=(=(,!..At/A/A!C  fd##DKIOOF--5-9:
++DKOOF#B  
? %&R0dkk4((%%dkk2DK[[//t{{+DK<;;/4+<*=Q@  NN9.@A		!%56INN9.@A		!%56I>>(,=>)Qq9!+!7:#%89 :B5)>>NN7,<=
 	t//06)L# 	g{; 	S %*>*J;< < '001EF*D1111!$.E!F&&~6'"">20.AA \\*ABN"">2u=1+
 !,G 5G 5G 5G 5G
 ^^J0CD
l3Jj#&&:+F(4L #D$7$7 D'')5  6 $0K ' < >%eRZZ88$)KKNa$7')zz%q'B'F'F'H'H $uQx 8 $ NN51 $0 !E, j&11

z* #[[$$"4::#,??'-';';J'G$I Je u% J
 3J>BCC7 &   * s%   "a"<Ba3"
a0/a03
bbc                     UR                  U R                  SS95        U R                  (       a  U R                  Ul        UR	                  U R                  5       5        g)z6
Set the boilerplate props for artists added to Axes.
Fr   N)r   r   r   rQ   set_transformget_transform)r8   as     r:   r   Legend._set_artist_propsn  sB     	
T__%_01;;YYAF	**,-r<   c                 ^   UnUSL U l         Uc,  [        R                  S   nU R                  (       d  US;   a  SnSU< 3nSU l        [        U[        5      (       a  UR                  5       S   S:X  a  UR                  S5      S	   nUR                  S
S5      U l        U R                  R                  5       S   U l        UR                  5       n[        U5      S	:  a(  US   S;   a  US   S:w  a  USSS2   nUS   S-   US	   -   n[        R                  " U R                  US9nO[        R                  " U5      (       a=  [        U5      n[        U5      S:w  d  [!        S U 5       5      (       d  [#        U5      eO8[        U[$        5      (       a  US:  d  US:  a  [#        U5      eO[#        U5      eU R                  (       a   U R                  (       a  [#        SU S35      eU R                  (       d  US:X  a  [#        S5      eU R                   nU R'                  U5        XPl         g)zj
Set the location of the legend.

.. versionadded:: 3.8

Parameters
----------
%(_legend_kw_set_loc_doc)s
Nz
legend.loc)r   r`   zupper rightz>loc must be string, coordinate tuple, or an integer 0-10, not r   ra   zoutside r'   zcenter r]   )r   r   rn    )r-   r   c              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frP   )r   numbersReal).0es     r:   	<genexpr>!Legend.set_loc.<locals>.<genexpr>  s     'QS
1gll(C(CSs   ')
   z'outside' option for loc='z0' keyword argument only works for figure legendszIAutomatic legend placement (loc='best') not implemented for figure legend)_loc_used_defaultr   r   r   _outside_locr   r   splitreplacer   r   check_getitemcodesr   r   rI   r   r   int_set_loc)r8   r-   loc0type_err_messagelocstmps         r:   r   Legend.set_locx  s
    !$;,,|,C;;3+#5#558G= !c3yy{1~*ii
+A.$'KK	2$>!$($5$5$;$;$=a$@!yy{t9q=T!W0A%AAw(*#DbDzq'C-$q'1C$$TZZS9C[[*C3x1}C'QS'Q$Q$Q !122 %RS!!Qw#( !122 # -..;;4,,,TF 3+ +, , {{sax ! ! $$c!$r<   c                 v    SU l         Xl        SU l        U R                  R	                  U R
                  5        g )NFT)r  	_loc_realstaler7   
set_offset_findoffset)r8   r-   s     r:   r  Legend._set_loc  s2     "'
##D$4$45r<   c                     Xl         g)zSet the number of columns.N)r   )r8   r   s     r:   	set_ncolsLegend.set_ncols  s    r<   c                     U R                   $ rP   )r  rA   s    r:   _get_locLegend._get_loc  s    ~~r<   c                    U R                   S:X  a  U R                  XU5      u  pgOU R                   [        R                  R	                  5       ;   aG  [
        R                  " SSX5      nU R                  U R                   UU R                  5       U5      u  pgOUU R                   u  pU R                  5       nUR                  UR                  U	-  -   UR                  UR                  U
-  -   pvXc-   Xt-   4$ )z%Helper function to locate the legend.r   )rK   _find_best_positionrh   r	  valuesr   from_bounds_get_anchored_bboxrE   x0rF   y0rG   )r8   rF   rG   xdescentydescentrendererxyr.   fxfys              r:   r  Legend._findoffset  s     99>++E8DDAqYY&,,--//##Aq%8D**499d+/+B+B+D+35DAq YYFB**,D77TZZ"_,dggb8H.Hq|Q\))r<   c                 >   U R                  5       (       d  g UR                  SU R                  5       S9  UR                  U R                  5      nU R
                  S;   aU  SU R                  U R                  -   -  U-  nU R                  R                  U R                  5       R                  U-
  5        U R                  R                  U5      nU R                  R                  UR                  5        U R                  R!                  U5        U R"                  (       a/  [%        U R                  40 U R&                  D6R)                  U5        U R                  R)                  U5        U R                  R)                  U5        UR+                  S5        SU l        g )Nr2   )gid)expandr   F)get_visible
open_groupget_gidpoints_to_pixelsr   r   r}   rx   r7   	set_widthrE   rF   get_window_extentr   
set_boundsboundsset_mutation_scaler   r   r   drawclose_groupr  )r8   r&  rv   padr.   s        r:   r8  Legend.draw  sE    !!H$,,.9,,T^^< ::#t))DNN:;hFC&&t'>'>'@'F'F'LM 11(;##DKK0++H5
 ;;4##:t'9'9:??Ih'h'X&
r<   )update_funcc                     U R                   $ )z=Return the global default handler map, shared by all legends._default_handler_map)clss    r:   get_default_handler_mapLegend.get_default_handler_map  s     '''r<   c                     Xl         g)z:Set the global default handler map, shared by all legends.Nr>  r@  r   s     r:   set_default_handler_mapLegend.set_default_handler_map  s
     $/ r<   c                 :    U R                   R                  U5        g)z=Update the global default handler map, shared by all legends.N)r?  r0   rD  s     r:   update_default_handler_map!Legend.update_default_handler_map   s     	  ''4r<   c                 h    U R                  5       nU R                  (       a  0 UEU R                  E$ U$ )z*Return this legend instance's handler map.)rA  r   )r8   default_handler_maps     r:   get_legend_handler_mapLegend.get_legend_handler_map%  s@    "::<++ D&C$*B*BC 	F1D	Fr<   c                      X   $ ! [         [        4 a     Of = f[        U5      R                  5        H  n X   s  $ ! [         a     M  f = f   g)a  
Return a legend handler from *legend_handler_map* that
corresponds to *orig_handler*.

*legend_handler_map* should be a dictionary object (that is
returned by the get_legend_handler_map method).

It first checks if the *orig_handle* itself is a key in the
*legend_handler_map* and return the associated value.
Otherwise, it checks for each of the classes in its
method-resolution-order. If no matching key is found, it
returns ``None``.
N)r   KeyErrorr   mro)legend_handler_maporig_handlehandle_types      r:   get_legend_handlerLegend.get_legend_handler+  sd    	%228$ 		,002K)66  3
 s    ?
AAc                    U R                   n/ n/ n/ nSU-  U R                  S-
  -  nX@R                  -  U-
  n	U R                  5       n
[        X5       H  u  pU R	                  X5      nUc@  [
        R                  " S[        U5      R                   S35        UR                  S5        MY  [        US[        SSU R                  S	9S
9n[        U R                  U-  U	SUS9nUR                  UR                  5        UR                  UR!                  XXO5      5        UR                  X45        M     / n[#        [$        [&        R(                  " XpR*                  5      5       Hq  nU VVs/ s H,  u  nn[-        SU R.                  U-  U(       a  UU/OUU/SS9PM.     nnnU(       a  SOSnUR                  [1        SU R2                  U-  UUS95        Ms     U R4                  S:X  a  SOSnU R6                  U-  n[-        SUSUUS9U l        [        S5      U l        [1        U R<                  U-  U R2                  U-  U R>                  U R:                  U R8                  /S9U l         U R@                  RC                  U RE                  SS95        U RF                  U R@                  l#        XPl$        X`l%        gs  snnf )z
Initialize the legend_box. The legend_box is an instance of
the OffsetBox, which is packed with legend handles and
texts. Once packed, their location is calculated during the
drawing time.
gffffff?gffffff?N$Legend does not support handles for z instances.
A proxy artist may be used instead.
See: https://matplotlib.org/stable/users/explain/axes/legend_guide.html#controlling-the-legend-entriesTbaseliner   )verticalalignmenthorizontalalignmentfontproperties)multilinebaseline	textpropsg        )rF   rG   r$  r%  r   )r:  sepchildrenalignr   )r:  r^  r`  r_  r.  fixed)r:  r^  r`  r   r_  r]   Fr   )&r   r{   rL  r   rT  r   warn_externalr   rV   appendr#   r   ru   r"   rz   _textlegend_artistfilterr   r   array_splitr   r    r|   r!   ry   r   r~   _legend_handle_boxr   rx   r   r7   r   r   rQ   r   r   )r8   r   r   rq   rv   	text_listhandle_listhandles_and_labelsdescentrG   rQ  rR  labelhandlertextbox	handlebox	columnboxhandles_and_labels_columnht	itemboxesr   r   r^  s                           r:   r   Legend._init_legend_boxE  s    >> 	 /T%6%6%<=---7 "88:"%g"6K--.@NG""C $[ 1 : :; <??@ ""4("5D-19C;A6:ii.AB
 (d.?.?(.J/513gG	   / ""7#8#89A$N O"))9*>?7 #7: 	
 *0R^^$6D*F% &?	@ &?TQ	 !Q%)%7%7(%B4?1a&aV'13 &?	  @ '2
wIW)-):):X)E+4.79 :*F  ::1xw  8+")a.1/33<#> "*""t~~'@'+'8'88'C)--1-C-C-1-D-D-FG
 	##DOOO$?@ $		
)7@s   .3J;c                   ^	 U R                   (       d   e/ n/ n/ nU R                  R                   GH  m	[        T	[        5      (       a>  UR                  T	R                  5       R                  T	R                  5       5      5        MW  [        T	[        5      (       a>  UR                  T	R                  5       R                  T	R                  5       5      5        M  [        T	[        5      (       a>  UR                  T	R                  5       R                  T	R                  5       5      5        M  [        T	[        5      (       a,  UR                  U	4S jT	R!                  5        5       5        GM>  [        T	["        5      (       aI  T	R%                  5       u  pVpx['        U5      (       a#  UR                  UR)                  U5      5        GM  GM  [        T	[*        5      (       d  GM  UR                  T	R-                  U5      5        GM     X#U4$ )z
Return display coordinates for hit testing for "best" positioning.

Returns
-------
bboxes
    List of bounding boxes of all patches.
lines
    List of `.Path` corresponding to each line.
offsets
    List of (x, y) offsets of all collection.
c              3   b   >#    U  H$  nTR                  5       R                  U5      v   M&     g 7frP   )r   transform_path)r   pathartists     r:   r  +Legend._auto_legend_data.<locals>.<genexpr>  s/      =); $113BB4HH);s   ,/)r   r^   	_childrenr   r   rc  r   ry  get_pathr   get_bboxtransformedget_data_transformr   r   extend	get_pathsr   _prepare_pointsr   rJ   r   r4  )
r8   r&  bboxeslinesoffsetsrJ   transOffsethoffsets_r{  s
            @r:   _auto_legend_dataLegend._auto_legend_data  s    {{{kk++F&&))((*99&//:KLNFI..OO%11&2K2K2MNPFE**((*99&//:KLNFN33 =)/)9)9);= =FJ//6<6L6L6N3	x==NN;#8#8#BC !FD))f66x@A% ,( g%%r<   c                 :    U R                   U R                  5       /$ rP   )r7   	get_framerA   s    r:   get_childrenLegend.get_children  s      $.."233r<   c                     U R                   $ )z:Return the `~.patches.Rectangle` used to frame the legend.)r   rA   s    r:   r  Legend.get_frame  s    r<   c                 t    U R                    Vs/ s H  n[        U[        5      (       d  M  UPM     sn$ s  snf )z4Return the list of `~.lines.Line2D`\s in the legend.)r   r   r   r8   rs  s     r:   	get_linesLegend.get_lines  s+    ..H.a*Q2G.HHHs   55c           
          [        SU R                   Vs/ s H  n[        U[        5      (       d  M  UPM     sn5      $ s  snf )z5Return the list of `~.patches.Patch`\s in the legend.r   )r
   r   r   r   r  s     r:   get_patchesLegend.get_patches  sA    7'+':': 5':!)!U3 ': 56 	65s   ?
?
c                 .    [        SU R                  5      $ )z1Return the list of `~.text.Text`\s in the legend.r   )r
   r   rA   s    r:   	get_textsLegend.get_texts  s    64::..r<   c                 ^    [         R                  " / SQUS9  Xl        XR                  l        g)z
Set the alignment of the legend title and the box of entries.

The entries are aligned as a single block, so that markers always
lined up.

Parameters
----------
alignment : {'center', 'left', 'right'}.

r   r   N)r   r3   r   r7   r`  )r8   r   s     r:   set_alignmentLegend.set_alignment  s&     	6)L#!*r<   c                 .    U R                   R                  $ )z)Get the alignment value of the legend box)r7   r`  rA   s    r:   get_alignmentLegend.get_alignment  s    %%%r<   c                    U R                   R                  R                  U5        U(       aA  U R                   R                  R                  S5        U R                   R                  S5        O@U R                   R                  R                  S5        U R                   R                  S5        Ub%  U R                   R                  R	                  U5        SU l        g)ax  
Set legend title and title style.

Parameters
----------
title : str
    The legend title.

prop : `.font_manager.FontProperties` or `str` or `pathlib.Path`
    The font properties of the legend title.
    If a `str`, it is interpreted as a fontconfig pattern parsed by
    `.FontProperties`.  If a `pathlib.Path`, it is interpreted as the
    absolute path to a font file.

TFN)r   rd  set_textset_visibleset_fontpropertiesr  )r8   r   ru   s      r:   r   Legend.set_title  s      	$$--e4""((44T:""..t4""((44U;""..u5""((;;DA
r<   c                 .    U R                   R                  $ )z1Return the `.Text` instance for the legend title.)r   rd  rA   s    r:   	get_titleLegend.get_title  s    %%+++r<   c                 t    Uc  U R                  SS9R                  5       nU R                  R                  US9$ )NTr   )r&  )r   _get_rendererr7   r4  r8   r&  s     r:   r4  Legend.get_window_extent  s;    D1??AH1181DDr<   c                 8    U R                   R                  U5      $ rP   )r7   r4  r  s     r:   get_tightbboxLegend.get_tightbbox!  s    11(;;r<   c                 6    U R                   R                  5       $ )z*Get whether the legend box patch is drawn.)r   r/  rA   s    r:   get_frame_onLegend.get_frame_on%  s    ++--r<   c                 H    U R                   R                  U5        SU l        g)zL
Set whether the legend box patch is drawn.

Parameters
----------
b : bool
TN)r   r  r  )r8   bs     r:   set_frame_onLegend.set_frame_on)  s     	$$Q'
r<   c                 `    U R                   c  U R                  R                  $ U R                   $ )z4Return the bbox that the legend will be anchored to.)_bbox_to_anchorr^   r.   rA   s    r:   rE   Legend.get_bbox_to_anchor6  s*    ';;###'''r<   c                    Uc  SU l         g[        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         Uc  [        U R                  R                  5      n[        U R                   U5      U 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 legend will be anchored to.

Parameters
----------
bbox : `~matplotlib.transforms.BboxBase` or tuple
    The bounding box can be specified in the following ways:

    - A `.BboxBase` instance
    - A tuple of ``(left, bottom, width, height)`` in the given
      transform (normalized axes coordinate if None)
    - A tuple of ``(left, bottom)`` where the width and height will be
      assumed to be zero.
    - *None*, to remove the bbox anchoring, and use the parent bbox.

transform : `~matplotlib.transforms.Transform`, optional
    A transform to apply to the bounding box. If not specified, this
    will use a transform to the bounding box of the parent.
NzInvalid bbox: r   r   r'   T)r  r   r   r   r   r   r   r   r   r^   r.   r   r  )r8   r.   rJ   lerrs        r:   rH   Legend.set_bbox_to_anchor=  s    ( <#'D h''#' CI AvQa!Q/#'#3#3T#:D '(8(89I.t/C/C/8 :
  C >$!89sBCs   B# #
C-B<<Cc           	      ~    [         R                  " XUU R                  UR                  U R                  5      -  5      $ )a  
Place the *bbox* inside the *parentbbox* according to a given
location code. Return the (x, y) coordinate of the bbox.

Parameters
----------
loc : int
    A location code in range(1, 11). This corresponds to the possible
    values for ``self._loc``, excluding "best".
bbox : `~matplotlib.transforms.Bbox`
    bbox to be placed, in display coordinates.
parentbbox : `~matplotlib.transforms.Bbox`
    A parent box which will contain the bbox, in display coordinates.
)r   r!  r}   r2  r   )r8   r-   r.   
parentbboxr&  s        r:   r!  Legend._get_anchored_bboxh  s;     ++z!:!:4>>!JJL 	Lr<   c                   ^ U R                   (       d   e[        R                  " 5       nU R                  U5      u  pVn[        R
                  " SSX5      n/ n	[        S[        U R                  5      5       H  n
U R                  XU R                  5       U5      u  p[        R
                  " XX5      m[        U4S jU 5       5      TR                  U5      -   TR                  U5      -   [        U4S jU 5       5      -   nU	R                  XX445        US:X  d  M    O   [        U	5      u    nu  pU R                   (       a2  [        R                  " 5       U-
  S:  a  ["        R$                  " S5        X4$ )z0Determine the best location to place the legend.r   r'   c              3   Z   >#    U  H   nTR                  UR                  5      v   M"     g 7frP   )count_containsverticesr   line	legendBoxs     r:   r  -Legend._find_best_position.<locals>.<genexpr>  s*      .',t %33DMMBB',s   (+c              3   D   >#    U  H  nUR                  TS S9v   M     g7f)F)filledN)intersects_bboxr  s     r:   r  r    s(      0). "11)E1J).s    zGCreating legend with loc="best" can be slow with large amounts of data.)r   timeperf_counterr  r   r   ranger   r	  r!  rE   sumr  count_overlapsrc  minr  r   rb  )r8   rF   rG   r&  
start_timer  r  r  r.   
candidatesidxr  r  badnessr  r  s                  @r:   r  Legend._find_best_position{  sf   {{{&&(
!%!7!7!Aw1e4
C

O,C**3+/+B+B+D+35DA ((u=I  .',. ."11':; #11&9:  0).0 0	0G waV45!|! -$ :1fq!!d&7&7&9J&F&J#$ tr<   c                 8    U R                   R                  U5      $ rP   )r   contains)r8   
mouseevents     r:   r  Legend.contains  s    ((44r<   c                     U(       a)  U R                   c  [        U UUS9U l         U R                   $ U R                   b  U R                   R                  5         SU l         U R                   $ )aj  
Enable or disable mouse dragging support of the legend.

Parameters
----------
state : bool
    Whether mouse dragging is enabled.
use_blit : bool, optional
    Use blitting for faster image composition. For details see
    :ref:`func-animation`.
update : {'loc', 'bbox'}, optional
    The legend parameter to be changed when dragged:

    - 'loc': update the *loc* parameter of the legend
    - 'bbox': update the *bbox_to_anchor* parameter of the legend

Returns
-------
`.DraggableLegend` or *None*
    If *state* is ``True`` this returns the `.DraggableLegend` helper
    instance. Otherwise this returns *None*.
Nr/   )r   r*   
disconnect)r8   r   r1   r0   s       r:   r   Legend.set_draggable  s_    . &"1$2:9?#A  ***,"DOr<   c                     U R                   SL$ )z@Return ``True`` if the legend is draggable, ``False`` otherwise.N)r   rA   s    r:   get_draggableLegend.get_draggable  s    d**r<   )"r   r  r   r   r   r7   rh  r   r  r  r   r   r  r   r   rQ   r}   rx   r~   r{   rz   r|   r   ry   r   r   rp   ro   r^   ru   rs   r   r  r   rP   )TrU   )PrV   rW   rX   rY   __doc__r   r	  zorderrl   r   interpdr6   r   r   r  r  r  propertyrK   r  r	   r8  r&   r(   HandlerStemr$   HandlerErrorbarr   HandlerLine2Dr   HandlerPatchr   HandlerStepPatchr   HandlerLineCollectionr   HandlerRegularPolyCollectionr   HandlerCircleCollectionr%   update_from_first_childrI   HandlerTupler   HandlerPathCollectionr   HandlerPolyCollectionr?  classmethodrA  rE  rH  rL  staticmethodrT  r   r  r  r  r  r  r  r  r  r   r  r4  r  r  r  
draw_framerE   rH   r!  r  r  r   r  rZ   r[   r\   s   @r:   rh   rh   V  s   
 Q2+112EF   !SID IDV. @% @%D6 Hh'D*"  J 	~113>99;,,.~**,>224<<>~JJL.@@Bn11&>>@~**,<<><<>
& ( ( / / 5 5F  2b*H%&N4 I6/+ &:,E<.	 J()VL&$L5 D+ +r<   rh   c              #   ~  #    / nU  Hq  nU/ S UR                    5       QUR                  Q-  n[        US5      (       d  M:  UR                   H'  nU/ S UR                    5       QUR                  Q-  nM)     Ms     0 [        R                  5       EU=(       d    0 En[        R                  nU H  nUR                  5       nUS:w  a  U" XW5      (       a  Uv   M,  U(       d  M5  UR                  S5      (       a  MM  U" XW5      (       a  M\  [        R                  " S[        U5      R                   S35        M     g7f)	z6Yield artists that can be used as handles in a legend.c              3   t   #    U  H.  n[        U[        [        [        [        45      (       d  M*  Uv   M0     g 7frP   r   r   r   r   r   r   r   s     r:   r  &_get_legend_handles.<locals>.<genexpr>  s+      CAAz4@A a   )8	8	parasitesc              3   t   #    U  H.  n[        U[        [        [        [        45      (       d  M*  Uv   M0     g 7frP   r  r  s     r:   r  r    s+      KA#Az4'HI ar  
_nolegend_r  rW  z| instances.
See: https://matplotlib.org/stable/tutorials/intermediate/legend_guide.html#implementing-a-custom-legend-handlerN)r}  
containershasattrr  rh   rA  rT  	get_label
startswithr   rb  r   rV   )	axsrQ  handles_originalaxaxxr   has_handlerr   rm  s	            r:   _get_legend_handlesr    sM     C C ]] 	
 2{##||  %%K K%% ^^%% %  $ 1V335 1(.B1K++K"  "L [%E%ELeE,,S1144C $V 5 56 7EEF  #s   ;D=BD=$D=<D=2D=c                     / n/ n[        X5       HV  nUR                  5       nU(       d  M  UR                  S5      (       a  M4  UR                  U5        UR                  U5        MX     X#4$ )z%Return handles and labels for legend.r  )r  r  r  rc  )r  rQ  r   r   r   rm  s         r:   _get_legend_handles_labelsr
    s`    GF%c>  "5))#..NN6"MM% 	 ?
 ?r<   )r   r   c                ,   [         R                  " [        5      nUR                  S5      nUc  Ub  U(       a  [        R
                  " SSS9  [        US5      (       aW  [        US5      (       aF  [        U5      [        U5      :w  a.  [        R                  " S[        U5       S[        U5       35        U(       a  U(       a  [        [        X5      6 u  pGO(Ub$  Uc!  U Vs/ s H  owR                  5       PM     nnGOUb-  Uc*  [        [        X5      U5       VVs/ s H  u  pxUPM	     nnnO[        U5      S	:X  a+  [        X5      u  pU(       d  [        R                  " S
5        O[        U5      S:X  aP  Uu  n[        S U 5       5      (       a  [        S5      e[        [        X5      U5       VVs/ s H  u  pxUPM	     nnnO8[        U5      S:X  a  USS u  pO![        R                  " SS[        U5      5      eXU4$ s  snf s  snnf s  snnf )a  
Get the handles and labels from the calls to either ``figure.legend``
or ``axes.legend``.

The parser is a bit involved because we support::

    legend()
    legend(labels)
    legend(handles, labels)
    legend(labels=labels)
    legend(handles=handles)
    legend(handles=handles, labels=labels)

The behavior for a mixture of positional and keyword handles and labels
is undefined and issues a warning; it will be an error in the future.

Parameters
----------
axs : list of `.Axes`
    If handles are not given explicitly, the artists in these Axes are
    used as handles.
*args : tuple
    Positional parameters passed to ``legend()``.
handles
    The value of the keyword argument ``legend(handles=...)``, or *None*
    if that keyword argument was not used.
labels
    The value of the keyword argument ``legend(labels=...)``, or *None*
    if that keyword argument was not used.
**kwargs
    All other keyword arguments passed to ``legend()``.

Returns
-------
handles : list of (`.Artist` or tuple of `.Artist`)
    The legend handles.
labels : list of str
    The legend labels.
kwargs : dict
    *kwargs* with keywords handles and labels removed.

r   Nz3.9zYou have mixed positional and keyword arguments, some input may be discarded.  This is deprecated since %(since)s and will become an error in %(removal)s.)message__len__z8Mismatched number of handles and labels: len(handles) = z len(labels) = r   zNo artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.r'   c              3   B   #    U  H  n[        U[        5      v   M     g 7frP   )r   r   )r   r  s     r:   r  %_parse_legend_args.<locals>.<genexpr>L  s     5fz!V$$fs   z\A single argument passed to legend() must be a list of labels, but found an Artist in there.r   r2   z0-2)logging	getLoggerrV   getr   warn_deprecatedr   r   rb  r   r  r  r
  anyr   nargs_error)	r  r   r   argskwargsloghandlersr   rm  s	            r:   _parse_legend_argsr    s   V 

H
%Czz-(Hv1tU.	0
 	##FI&&LCK' --0\N ;,,/K=: 	; 6s734		3:;7""$7;		 -c<fEGE ,f6E 	 G 
Ta4SC<=
 
Ta5f555 L M M
 -c<fEGE ,f6E 	 G 
Tar( xD	::F""? <G$Gs   #HH
7HrP   )Ir  r   r  r   r  numpyr   
matplotlibr   r   r   r   r   r   matplotlib.artistr   r	   matplotlib.cbookr
   matplotlib.font_managerr   matplotlib.linesr   matplotlib.patchesr   r   r   r   r   matplotlib.collectionsr   r   r   r   r   r   matplotlib.textr   matplotlib.transformsr   r   r   r   r   matplotlib.offsetboxr   r   r    r!   r"   r#   matplotlib.containerr$   r%   r&   r]   r(   r*   _legend_kw_doc_base_loc_doc_base_loc_doc_bestformat_legend_kw_axes_str  register_outside_doc_legend_kw_figure_st_legend_kw_both_st_legend_kw_set_loc_strh   r  r
  r  rk   r<   r:   <module>r1     s  .       A A 9 ( 2 #+ ++ + ! A A D 
 P O )4( )4X^ @%N 0B+R  9      ,>  ?
 / ,  8      .B  C !V+\  C  
     +=  > !V+\  C      3H  Ir+V r+nD	 ,0 _#r<   