
    P/Pht                        d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ d Z G d d	          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d  d!e          Z G d" d#e          Z G d$ d%e          ZdS )&a  
Default legend handlers.

.. important::

    This is a low-level legend API, which most end users do not need.

    We recommend that you are familiar with the :ref:`legend guide
    <legend_guide>` before reading this documentation.

Legend handlers are expected to be a callable object with a following
signature::

    legend_handler(legend, orig_handle, fontsize, handlebox)

Where *legend* is the legend itself, *orig_handle* is the original
plot, *fontsize* is the fontsize in pixels, and *handlebox* is an
`.OffsetBox` instance. Within the call, you should create relevant
artists (using relevant properties from the *legend* and/or
*orig_handle*) and add them into the *handlebox*. The artists need to
be scaled according to the *fontsize* (note that the size is in pixels,
i.e., this is dpi-scaled value).

This module includes definition of several legend handler classes
derived from the base class (HandlerBase) with the following method::

    def legend_artist(self, legend, orig_handle, fontsize, handlebox)
    )cycleN)cbookLine2D)	Rectanglec                     t          t          |                                          d           }||                     |           d S d S N)nextiterget_childrenupdate_from)tgtsrcfirst_childs      Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/matplotlib/legend_handler.pyupdate_from_first_childr   (   sK    tC,,..//66K$$$$$     c                   >    e Zd ZdZddZd Zd Zd Zd Zd	 Z	d
 Z
dS )HandlerBasea  
    A base class for default legend handlers.

    The derived classes are meant to override *create_artists* method, which
    has the following signature::

      def create_artists(self, legend, orig_handle,
                         xdescent, ydescent, width, height, fontsize,
                         trans):

    The overridden method needs to create artists of the given
    transform that fits in the given dimension (xdescent, ydescent,
    width, height) that are scaled by fontsize if necessary.

            Nc                 2    ||c| _         | _        || _        dS )ak  
        Parameters
        ----------
        xpad : float, optional
            Padding in x-direction.
        ypad : float, optional
            Padding in y-direction.
        update_func : callable, optional
            Function for updating the legend handler properties from another
            legend handler, used by `~HandlerBase.update_prop`.
        N)_xpad_ypad_update_prop_func)selfxpadypadupdate_funcs       r   __init__zHandlerBase.__init__>   s"     "&t
DJ!,r   c                 p    | j         |                     ||           d S |                      ||           d S r	   )r   _default_update_propr   legend_handleorig_handles      r   _update_propzHandlerBase._update_propM   sC    !)%%m[AAAAA""=+>>>>>r   c                 0    |                     |           d S r	   )r   r"   s      r   r!   z HandlerBase._default_update_propS   s    !!+.....r   c                     |                      ||           |                    |           |                    d            |                    d            d S r	   )r%   _set_artist_propsset_clip_boxset_clip_pathr   r#   r$   legends       r   update_propzHandlerBase.update_propV   sZ    -555  ///""4(((##D)))))r   c                 v    || j         |z  z
  }|| j        |z  z
  }|| j         |z  z
  }|| j        |z  z
  }||||fS r	   )r   r   )r   r,   r$   xdescentydescentwidthheightfontsizes           r   adjust_drawing_areazHandlerBase.adjust_drawing_area^   sW     dj833dj833
X--$*x//5&00r   c                 
   |                      |||j        |j        |j        |j        |          \  }}}}|                     ||||||||                                          }	|	D ]}
|                    |
           |	d         S )a.  
        Return the artist that this HandlerBase generates for the given
        original artist/handle.

        Parameters
        ----------
        legend : `~matplotlib.legend.Legend`
            The legend for which these legend artists are being created.
        orig_handle : :class:`matplotlib.artist.Artist` or similar
            The object for which these legend artists are being created.
        fontsize : int
            The fontsize in pixels. The artists being created should
            be scaled according to the given fontsize.
        handlebox : `~matplotlib.offsetbox.OffsetBox`
            The box which has been created to hold this legend entry's
            artists. Artists created in the `legend_artist` method must
            be added to this handlebox inside this method.

        r   )r4   r/   r0   r1   r2   create_artistsget_transform
add_artist)r   r,   r$   r3   	handleboxr/   r0   r1   r2   artistsas              r   legend_artistzHandlerBase.legend_artistg   s    * -1,D,D#Y%7)"2	- -)(E6
 %%fk&.%&.	0G0G0I0IK K
  	$ 	$A  #### qzr   c	                      t          d          )a  
        Return the legend artists generated.

        Parameters
        ----------
        legend : `~matplotlib.legend.Legend`
            The legend for which these legend artists are being created.
        orig_handle : `~matplotlib.artist.Artist` or similar
            The object for which these legend artists are being created.
        xdescent, ydescent, width, height : int
            The rectangle (*xdescent*, *ydescent*, *width*, *height*) that the
            legend artists being created should fit within.
        fontsize : int
            The fontsize in pixels. The legend artists being created should
            be scaled according to the given fontsize.
        trans : `~matplotlib.transforms.Transform`
            The transform that is applied to the legend artists being created.
            Typically from unit coordinates in the handler box to screen
            coordinates.
        zDerived must override)NotImplementedError)	r   r,   r$   r/   r0   r1   r2   r3   transs	            r   r6   zHandlerBase.create_artists   s    . ""9:::r   )r   r   N)__name__
__module____qualname____doc__r   r%   r!   r-   r4   r<   r6    r   r   r   r   .   s         - - - -? ? ?/ / /* * *1 1 1# # #J; ; ; ; ;r   r   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )HandlerNpointszM
    A legend handler that shows *numpoints* points in the legend entry.
    333333?Nc                 V     t                      j        di | || _        || _        dS )a  
        Parameters
        ----------
        marker_pad : float
            Padding between points in legend entry.
        numpoints : int
            Number of points to show in legend entry.
        **kwargs
            Keyword arguments forwarded to `.HandlerBase`.
        NrD   )superr   
_numpoints_marker_pad)r   
marker_pad	numpointskwargs	__class__s       r   r   zHandlerNpoints.__init__   s7     	""6"""#%r   c                 ,    | j         |j        S | j         S r	   )rJ   rM   r   r,   s     r   get_numpointszHandlerNpoints.get_numpoints   s    ?"##?"r   c                     |                      |          }|dk    r.| j        |z  }t          j        | |z   | |z   |z
  |          }	|	}
n| | |z   g}	| d|z  z   g}
|	|
fS )N         ?)rR   rK   nplinspace)r   r,   r/   r0   r1   r2   r3   rM   padxdataxdata_markers              r   	get_xdatazHandlerNpoints.get_xdata   s    &&v..	q=="X-CK	C!)	E 1C 7 )+ +E !LLY	E 12E%Ie34Ll""r   )rG   N)r@   rA   rB   rC   r   rR   r[   __classcell__rO   s   @r   rF   rF      se         & & & & & & # # ## # # # # # #r   rF   c                   *     e Zd ZdZd fd	Zd Z xZS )HandlerNpointsYoffsetsz
    A legend handler that shows *numpoints* in the legend, and allows them to
    be individually offset in the y-direction.
    Nc                 L     t                      j        dd|i| || _        dS )aL  
        Parameters
        ----------
        numpoints : int
            Number of points to show in legend entry.
        yoffsets : array of floats
            Length *numpoints* list of y offsets for each point in
            legend entry.
        **kwargs
            Keyword arguments forwarded to `.HandlerNpoints`.
        rM   NrD   )rI   r   	_yoffsets)r   rM   yoffsetsrN   rO   s       r   r   zHandlerNpointsYoffsets.__init__   s2     	7797777!r   c                 b    | j         ||j        z  }n|t          j        | j                   z  }|S r	   ra   _scatteryoffsetsrV   asarrayr   r,   r/   r0   r1   r2   r3   ydatas           r   	get_ydataz HandlerNpointsYoffsets.get_ydata   s4    >!V44EERZ777Er   NN)r@   rA   rB   rC   r   ri   r\   r]   s   @r   r_   r_      sV         
" " " " " "      r   r_   c                       e Zd ZdZd ZdS )HandlerLine2DCompoundz
    Original handler for `.Line2D` instances, that relies on combining
    a line-only with a marker-only artist.  May be deprecated in the future.
    c	                    |                      ||||||          \  }	}
t          j        |	||z
  dz            }t          |	|          }|                     |||           |                    d           |                    d           t          |
|d t          |
                             }|                     |||           |                    d           |j	        dk    r1|
                                |j	        z  }|                    |           ||_        |                    |           |                    |           ||gS )N   default NonerT   )r[   rV   	full_liker   r-   set_drawstyle
set_markerlenset_linestylemarkerscaleget_markersizeset_markersize
_legmarkerset_transform)r   r,   r$   r/   r0   r1   r2   r3   r?   rY   rZ   rh   leglinelegline_markernewszs                  r   r6   z$HandlerLine2DCompound.create_artists   s]    #nnVXx-2FHF F| Ufx&71%<>>&&+v666i(((2e4FS5F5F4F.GHHf===$$V,,,"""1133f6HHE))%000 ,e$$$$$U+++((r   Nr@   rA   rB   rC   r6   rD   r   r   rl   rl      s-         
) ) ) ) )r   rl   c                       e Zd ZdZd ZdS )HandlerLine2Dz
    Handler for `.Line2D` instances.

    See Also
    --------
    HandlerLine2DCompound : An earlier handler implementation, which used one
                            artist for the line and another for the marker(s).
    c	                    |                      ||||||          \  }	}
d }|                     |          dk    r%t          j        |	d         |	d         d          }	dg}t          j        |	||z
  dz            }t          |	||          }|                     |||           |j        dk    r1|                                |j        z  }|	                    |           |
                    |           |gS )NrT   r      rn   )	markevery)r[   rR   rV   rW   rr   r   r-   rw   rx   ry   r{   )r   r,   r$   r/   r0   r1   r2   r3   r?   rY   rZ   r   rh   r|   r~   s                  r   r6   zHandlerLine2D.create_artists  s    #nnVXx-2FHF F| 	f%%** Ka%)Q77EIUVh%6!$;<<;;;+v666""**,,v/AAE""5)))e$$$yr   Nr   rD   r   r   r   r     s-             r   r   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )HandlerPatchz)
    Handler for `.Patch` instances.
    Nc                 H     t                      j        di | || _        dS )a  
        Parameters
        ----------
        patch_func : callable, optional
            The function that creates the legend key artist.
            *patch_func* should have the signature::

                def patch_func(legend=legend, orig_handle=orig_handle,
                               xdescent=xdescent, ydescent=ydescent,
                               width=width, height=height, fontsize=fontsize)

            Subsequently, the created artist will have its ``update_prop``
            method called and the appropriate transform will be applied.

        **kwargs
            Keyword arguments forwarded to `.HandlerBase`.
        NrD   )rI   r   _patch_func)r   
patch_funcrN   rO   s      r   r   zHandlerPatch.__init__?  s0    $ 	""6"""%r   c           	      z    | j         t          | | f||          }n|                      |||||||          }|S )Nxyr1   r2   )r,   r$   r/   r0   r1   r2   r3   )r   r   )	r   r,   r$   r/   r0   r1   r2   r3   ps	            r   _create_patchzHandlerPatch._create_patchT  sf    #xi(3 %f6 6 6AA   K*2X',Vh ! P PA r   c	           	          |                      |||||||          }	|                     |	||           |	                    |           |	gS r	   )r   r-   r{   
r   r,   r$   r/   r0   r1   r2   r3   r?   r   s
             r   r6   zHandlerPatch.create_artists_  s[     v{'5&(L LK000	s
r   r	   )r@   rA   rB   rC   r   r   r6   r\   r]   s   @r   r   r   :  se         & & & & & &*	 	 	      r   r   c                   D    e Zd ZdZed             Zed             Zd ZdS )HandlerStepPatchzA
    Handler for `~.matplotlib.patches.StepPatch` instances.
    c                 T    t          | | f|||                                           S )N)r   r1   r2   color)r   get_facecolor)r$   r/   r0   r1   r2   s        r   r   zHandlerStepPatch._create_patchn  s;    hY	2% &k.G.G.I.IK K K 	Kr   c                    t          d|g|dz  |dz  g|                                 |                                 |                                           }|                    d           |                    d           |S )Nr   rn   )r   	linestyle	linewidthro   rp   )r   get_edgecolorget_linestyleget_linewidthrs   rt   )r$   r1   r2   r|   s       r   _create_linezHandlerStepPatch._create_lines  s     !UfQhq%9*88::#.#<#<#>#>#.#<#<#>#>   	i(((2r   c	                    |                                 s|                                1|                     |||||          }	|                     |	||           n|                     |||          }	|	                    |           |	gS r	   )get_fill	get_hatchr   r-   r   r{   r   s
             r   r6   zHandlerStepPatch.create_artists  s     !! 	>k&;&;&=&=&I"";(E#)+ +AQV4444!!+uf==A	s
r   N)r@   rA   rB   rC   staticmethodr   r   r6   rD   r   r   r   r   i  sf          K K \K   \
 
 
 
 
r   r   c                   $    e Zd ZdZd Zd Zd ZdS )HandlerLineCollectionz2
    Handler for `.LineCollection` instances.
    c                 ,    | j         |j        S | j         S r	   rJ   scatterpointsrQ   s     r   rR   z#HandlerLineCollection.get_numpoints      ?"''?"r   c                    |                                 d         }|j        d         }|                                d         }|                    |           |                    |           |                    |           d S Nr   )get_linewidths_us_linestyles
get_colors	set_colorrv   set_linewidth)r   r#   r$   lwdashesr   s         r   r!   z*HandlerLineCollection._default_update_prop  s}    ''))!,+A.&&((+&&&##F+++##B'''''r   c	                     |                      ||||||          \  }	}
t          j        |	||z
  dz            }t          |	|          }|                     |||           |                    |           |gS )Nrn   )r[   rV   rr   r   r-   r{   )r   r,   r$   r/   r0   r1   r2   r3   r?   rY   rZ   rh   r|   s                r   r6   z$HandlerLineCollection.create_artists  s     #nnVXx-2FHF F|UVh%6!$;<<&&+v666e$$$yr   N)r@   rA   rB   rC   rR   r!   r6   rD   r   r   r   r     sK         # # #( ( (    r   r   c                   B     e Zd ZdZd	 fd	Zd Zd Zd Zd Zd Z	 xZ
S )
HandlerRegularPolyCollectionz'Handler for `.RegularPolyCollection`\s.Nc                 L     t                      j        dd|i| || _        d S )Nrb   rD   )rI   r   _sizes)r   rb   sizesrN   rO   s       r   r   z%HandlerRegularPolyCollection.__init__  s0    55(5f555r   c                 ,    | j         |j        S | j         S r	   r   rQ   s     r   rR   z*HandlerRegularPolyCollection.get_numpoints  r   r   c                 x   | j         |                                }t          |          sdg}t          |          |j        dz  z  }	t          |          |j        dz  z  }
|                     |          }|dk     rd|	|
z   z  |	|
gd |         }n)|	|
z
  }|t          j        dd|          z  |
z   }n| j         }|S )NrT   rn      rU   r   )	r   	get_sizesru   maxrw   minrR   rV   rW   )r   r,   r$   r/   r0   r1   r2   r3   handle_sizessize_maxsize_minrM   r   rngs                 r   r   z&HandlerRegularPolyCollection.get_sizes  s    ;&0022L|$$ # !s<((6+=+BBH<((6+=+BBH**622I1}}x(23X!##-I:/  (*bk!Q	:::XEKEr   c                     |                      ||           |                    |                    d                     |                    d            |                    d            d S )NF)root)r%   
set_figure
get_figurer)   r*   r+   s       r   r-   z(HandlerRegularPolyCollection.update_prop  sk    -555  !2!2!2!>!>???""4(((##D)))))r   c                      t          |          |                                |                                |||          S )N)rotationr   offsetsoffset_transform)typeget_numsidesget_rotationr   r$   r   r   r   s        r   create_collectionz.HandlerRegularPolyCollection.create_collection  sI     tK  $$&& --//u.>
 
 
 	
r   c	           
      l   |                      ||||||          \  }	}
|                     ||||||          }|                     |||||||          }|                     ||t	          t          |
|                    |          }|                     |||           |                    |           |gS N)r   r   )r[   ri   r   r   listzipr-   set_offset_transform)r   r,   r$   r/   r0   r1   r2   r3   r?   rY   rZ   rh   r   r   s                 r   r6   z+HandlerRegularPolyCollection.create_artists  s     #nnVXx-2FHF F| vx$fh8 8 v{Hh$fh8 8 ""\51122U # L L 	K000	u%%%s
r   rj   )r@   rA   rB   rC   r   rR   r   r-   r   r6   r\   r]   s   @r   r   r     s        22     
# # #  ** * *
 
 
      r   r   c                       e Zd ZdZd ZdS )HandlerPathCollectionzDHandler for `.PathCollection`\s, which are used by `~.Axes.scatter`.c                 l     t          |          |                                d         g|||          S )Nr   )r   r   r   )r   	get_pathsr   s        r   r   z'HandlerPathCollection.create_collection  sB     tK  ""$$Q'(.>
 
 
 	
r   Nr@   rA   rB   rC   r   rD   r   r   r   r     s)        OO
 
 
 
 
r   r   c                       e Zd ZdZd ZdS )HandlerCircleCollectionz"Handler for `.CircleCollection`\s.c                 8     t          |          |||          S r   )r   r   s        r   r   z)HandlerCircleCollection.create_collection  s/     tK  75EG G G 	Gr   Nr   rD   r   r   r   r     s.        --G G G G Gr   r   c                   4     e Zd ZdZ	 	 d fd	Zd Zd Z xZS )	HandlerErrorbarzHandler for Errorbars.rU   NrG   c                 \    || _         || _         t                      j        d||d| d S )N)rL   rM   rD   )
_xerr_size
_yerr_sizerI   r   )r   	xerr_size	yerr_sizerL   rM   rN   rO   s         r   r   zHandlerErrorbar.__init__  s=     $#NJ)NNvNNNNNr   c                 F    | j         |z  }| j        |}n
| j        |z  }||fS r	   )r   r   )	r   r,   r/   r0   r1   r2   r3   r   r   s	            r   get_err_sizezHandlerErrorbar.get_err_size  s4    Oh.	?"!II(2I)##r   c	                    |\  }	}
}|                      ||||||          \  }}t          j        |||z
  dz            }t          ||          }t          j        |          }t          j        |d t          |                             }|                     ||||||          \  t          ||          }|	+|                    d           |                    d           n|                     ||	|           |	                    d           |
                    d           |                     ||	|           |                    d           |j        dk    r1|                                |j        z  }|                    |           g }g }|j        rfdt!          ||          D             }t#          j        |          }|                     ||d         |           |                    |           |
rt          |z
  |          }t          |z   |          }|                     ||
d         |           |                     ||
d         |           |
                    d	           |
                    d	           |                    |           |                    |           |j        rfd
t!          ||          D             }t#          j        |          }|                     ||d         |           |                    |           |
rt          ||z
            }t          ||z             }|                     ||
d         |           |                     ||
d         |           |
                    d           |
                    d           |                    |           |                    |           g ||||}|D ]}|                    |           |S )Nrn   Fro   nonerq   rT   c                 2    g | ]\  }}|z
  |f|z   |ffS rD   rD   ).0xyr   s      r   
<listcomp>z2HandlerErrorbar.create_artists.<locals>.<listcomp>I  sJ     B B BA 9}a(1y=!*<= B B Br   r   |c                 2    g | ]\  }}||z
  f||z   ffS rD   rD   )r   r   r   r   s      r   r   z2HandlerErrorbar.create_artists.<locals>.<listcomp>[  sJ     B B BA !i-(1a)m*<= B B Br   _)r[   rV   rr   r   rf   ru   r   set_visibler-   rs   rt   rv   rw   rx   ry   has_xerrr   mcollLineCollectionappendhas_yerrr{   )r   r,   r$   r/   r0   r1   r2   r3   r?   	plotlinescaplinesbarlinecolsrY   rZ   rh   r|   ydata_markerr}   r~   handle_barlinecolshandle_caplinesvertscollcapline_leftcapline_rightr:   artistr   r   s                              @@r   r6   zHandlerErrorbar.create_artists  s    ,7(	8["nnVXx-2FHF F| UVh%6!$;<<&&z,//z%(:\):):(:";<<#00816 J  J	9  l;; &&&&&u----Wi888!!),,,v&&&^Y???((000!Q&&&5577&:LL--e444 	6B B B B!$\<!@!@B B BE'..DT;q>6:::%%d+++ 	6%lY&>MM &|i'? N N  x{FCCC  VDDD'',,,((---&&|444&&}555 	6B B B B!$\<!@!@B B BE'..DT;q>6:::%%d+++ 	6%lL94LMM &|\I5M N N  x{FCCC  VDDD'',,,((---&&|444&&}555

"1
3:
<J
  	( 	(F  ''''r   )rU   NrG   N)r@   rA   rB   rC   r   r   r6   r\   r]   s   @r   r   r   	  st          04+/O O O O O O	$ 	$ 	$R R R R R R Rr   r   c                   :     e Zd ZdZ	 	 d fd	Zd Zd Zd Z xZS )	HandlerStemz6
    Handler for plots produced by `~.Axes.stem`.
    rG   Nc                 P     t                      j        d|||d| || _        dS )a  
        Parameters
        ----------
        marker_pad : float, default: 0.3
            Padding between points in legend entry.
        numpoints : int, optional
            Number of points to show in legend entry.
        bottom : float, optional

        yoffsets : array of floats, optional
            Length *numpoints* list of y offsets for each point in
            legend entry.
        **kwargs
            Keyword arguments forwarded to `.HandlerNpointsYoffsets`.
        )rL   rM   rb   NrD   )rI   r   _bottom)r   rL   rM   bottomrb   rN   rO   s         r   r   zHandlerStem.__init__y  sD    " 	 	6J)"*	6 	6.4	6 	6 	6r   c                 n    | j         |d|j        z  dz   z  }n|t          j        | j                   z  }|S )NrU   rd   rg   s           r   ri   zHandlerStem.get_ydata  s>    >!cF$;;cABEERZ777Er   c	                 j   |\  }	}
}t          |
t          j                  }|                     ||||||          \  }}|                     ||||||          }| j        dn| j        t          ||d t          |                             }|                     ||	|           fdt          ||          D             }|rQt          j        | | j                  5  |D ]}|                     ||
|           	 d d d            n# 1 swxY w Y   n-t          ||
          D ]\  }}|                     |||           t          t          j        |          t          j        |          gg          }|                     |||           g |||}|D ]}|                    |           |S )Nr   c                 >    g | ]\  }}t          ||g|g          S rD   r   )r   r   r   r  s      r   r   z.HandlerStem.create_artists.<locals>.<listcomp>  s?     ? ? ?!Q  A44 ? ? ?r   )r   )
isinstancer   r   r[   ri   r  r   ru   r-   r   r   _setattr_cm_copy_collection_propsrV   r   r   r{   )r   r,   r$   r/   r0   r1   r2   r3   r?   
markerline	stemlinesbaselineusing_linecollrY   rZ   rh   leg_markerlineleg_stemlineslinelmmleg_baseliner:   r   r  s                           @r   r6   zHandlerStem.create_artists  se    +6'
Ix $Iu/CDD"nnVXx-2FHF F| vx$fh8 8 <FF\Fe4FS5F5F4F.GHHV<<<? ? ? ?%(u%=%=? ? ?  
	0 "D,GI I I > >) > >D$$T9f====>> > > > > > > > > > > > > > > ]I66 0 0A  Q////rve}}bfUmm<%v.0 0x888@M@<@@ 	( 	(F  ''''s   D		DDc                     |                     |                                d                    |                    |                                d                    dS )zt
        Copy properties from the `.LineCollection` *orig_handle* to the
        `.Line2D` *legend_handle*.
        r   N)r   	get_colorrv   r   r"   s      r   r	  z"HandlerStem._copy_collection_props  sT    
 	 5 5 7 7 :;;;##K$=$=$?$?$BCCCCCr   )rG   NNN)	r@   rA   rB   rC   r   ri   r6   r	  r\   r]   s   @r   r   r   t  s          26'+     *  . . .`D D D D D D Dr   r   c                   *     e Zd ZdZd fd	Zd Z xZS )HandlerTuplez
    Handler for Tuple.
    rT   Nc                 V    || _         || _         t                      j        di | dS )a  
        Parameters
        ----------
        ndivide : int or None, default: 1
            The number of sections to divide the legend area into.  If None,
            use the length of the input tuple.
        pad : float, default: :rc:`legend.borderpad`
            Padding in units of fraction of font size.
        **kwargs
            Keyword arguments forwarded to `.HandlerBase`.
        NrD   )_ndivide_padrI   r   )r   ndividerX   rN   rO   s       r   r   zHandlerTuple.__init__  s6      	""6"""""r   c	                    |                                 }	| j        t          |          }
n| j        }
| j        |j        |z  }n
| j        |z  }|
dk    r|||
dz
  z  z
  |
z  }t          |||z   t          j        |
          z  z
            }g }|D ]V}|                    |	|          }|	                    ||t          |          |||||          }|                    |           W|S )NrT   )get_legend_handler_mapr  ru   r  	borderpadr   rV   arangeget_legend_handlerr6   r
   extend)r   r,   r$   r/   r0   r1   r2   r3   r?   handler_mapr  rX   	xds_cyclea_listhandle1handler_a_lists                    r   r6   zHandlerTuple.create_artists  s    3355= +&&GGmG9"X-CC)h&CQ;;SGaK00G;E(eckRYw5G5G%GGHH	" 	# 	#G//WEEG,,Y5&(EK KG MM'""""r   )rT   N)r@   rA   rB   rC   r   r6   r\   r]   s   @r   r  r    sV         # # # # # #       r   r  c                       e Zd ZdZd Zd ZdS )HandlerPolyCollectionza
    Handler for `.PolyCollection` used in `~.Axes.fill_between` and
    `~.Axes.stackplot`.
    c                    d }d } ||                                           |_         ||                                          |_        |j        |_        |j        |_        |                                |_        |                                |_	        |j
        |_
        |                     ||                                                     |                     ||                                                     |                     ||                                                     |                    |                                           d S )Nc                 F    | j         dk    rdS t          | d                   S )Nr   )r   r   r   r   )sizetuple)colorss    r   first_colorz7HandlerPolyCollection._update_prop.<locals>.first_color
  s&    {a#|###r   c                 4    t          |           r| d         S d S r   )ru   )
prop_arrays    r   	get_firstz5HandlerPolyCollection._update_prop.<locals>.get_first  s    : !!}$tr   )r   
_facecolorr   
_edgecolor_original_facecolor_original_edgecolorr   _fillr   _hatch_hatch_colorr   r   rv   get_linestylesr{   get_transformsr   r   )r   r#   r$   r/  r2  s        r   r%   z"HandlerPolyCollection._update_prop	  sK   	$ 	$ 	$
	 	 	 $/;{/H/H/J/J#K#K #.;{/H/H/J/J#K#K ,7,K),7,K))2244*4466%0%="##IIk.H.H.J.J$K$KLLL##IIk.H.H.J.J$K$KLLL##IIk.H.H.J.J$K$KLLL  !7!7!9!9:::::r   c	                     t          | | f||          }	|                     |	||           |	                    |           |	gS )Nr   )r   r-   r{   r   s
             r   r6   z$HandlerPolyCollection.create_artists&  sY     8)hY/!&2 2 2K000	s
r   N)r@   rA   rB   rC   r%   r6   rD   r   r   r)  r)    s<         ; ; ;:    r   r)  )rC   	itertoolsr   numpyrV   
matplotlibr   matplotlib.linesr   matplotlib.patchesr   matplotlib.collectionscollectionsr   r   r   rF   r_   rl   r   r   r   r   r   r   r   r   r   r  r)  rD   r   r   <module>rD     sC   :                 # # # # # # ( ( ( ( ( ( & & & & & &% % %u; u; u; u; u; u; u; u;p'# '# '# '# '#[ '# '# '#T    ^   <") ") ") ") ")N ") ") ")J$ $ $ $ $N $ $ $N, , , , ,; , , ,^" " " " "{ " " "J    M   @F F F F F#9 F F FR
 
 
 
 
8 
 
 
G G G G G: G G Gh h h h hm h h hVXD XD XD XD XD( XD XD XDv2 2 2 2 2; 2 2 2j) ) ) ) )K ) ) ) ) )r   