
    *g                     L   d dl mZ d dlmZmZ d dlZd dlmZmZ d dl	Z	d dl
Zd dlZ
d dlZd dlmZ d dlmZ d dlmZ d dlmc mZ erd dlmZ 	 	 	 d	 	 	 	 	 	 	 dd	Z	 	 	 	 	 	 	 	 	 	 dd
ZddZ	 	 	 	 	 	 ddZddZ	 	 	 	 ddZ ddZ!ddZ"ddZ#d dZ$d!dZ%d!dZ&d"dZ'd#dZ(y)$    )annotations)
CollectionIteratorN)TYPE_CHECKINGcast)MatplotlibColor)find_stack_level)is_list_like)Colormapc                p    t        |t              r|S t        ||||       }t        t	        ||             S )a  
    Get standard colors based on `colormap`, `color_type` or `color` inputs.

    Parameters
    ----------
    num_colors : int
        Minimum number of colors to be returned.
        Ignored if `color` is a dictionary.
    colormap : :py:class:`matplotlib.colors.Colormap`, optional
        Matplotlib colormap.
        When provided, the resulting colors will be derived from the colormap.
    color_type : {"default", "random"}, optional
        Type of colors to derive. Used if provided `color` and `colormap` are None.
        Ignored if either `color` or `colormap` are not None.
    color : dict or str or sequence, optional
        Color(s) to be used for deriving sequence of colors.
        Can be either be a dictionary, or a single color (single color string,
        or sequence of floats representing a single color),
        or a sequence of colors.

    Returns
    -------
    dict or list
        Standard colors. Can either be a mapping if `color` was a dictionary,
        or a list of colors with a length of `num_colors` or more.

    Warns
    -----
    UserWarning
        If both `colormap` and `color` are provided.
        Parameter `color` will override.
    colorcolormap
color_type
num_colorsr   )
isinstancedict_derive_colorslist_cycle_colors)r   r   r   r   colorss        k/var/www/html/articles-backend/trend/venv/lib/python3.12/site-packages/pandas/plotting/_matplotlib/style.pyget_standard_colorsr      s>    L %	F f<==    c                    | |t        ||      S | ,|t        j                  dt                      t	        |       S t        ||      S )aa  
    Derive colors from either `colormap`, `color_type` or `color` inputs.

    Get a list of colors either from `colormap`, or from `color`,
    or from `color_type` (if both `colormap` and `color` are None).

    Parameters
    ----------
    color : str or sequence, optional
        Color(s) to be used for deriving sequence of colors.
        Can be either be a single color (single color string, or sequence of floats
        representing a single color), or a sequence of colors.
    colormap : :py:class:`matplotlib.colors.Colormap`, optional
        Matplotlib colormap.
        When provided, the resulting colors will be derived from the colormap.
    color_type : {"default", "random"}, optional
        Type of colors to derive. Used if provided `color` and `colormap` are None.
        Ignored if either `color` or `colormap`` are not None.
    num_colors : int
        Number of colors to be extracted.

    Returns
    -------
    list
        List of colors extracted.

    Warns
    -----
    UserWarning
        If both `colormap` and `color` are provided.
        Parameter `color` will override.
    r   zC'color' and 'colormap' cannot be used simultaneously. Using 'color')
stacklevel)_get_colors_from_colormapwarningswarnr	   _get_colors_from_color_get_colors_from_color_typer   s       r   r   r   P   sW    N }-(jII		MMU+- &e,,*:*MMr   c              #     K   t        |t        |             }t        j                  t        j                  |       |      E d{    y7 w)zCycle colors until achieving max of `num_colors` or length of `colors`.

    Extra colors will be ignored by matplotlib if there are more colors
    than needed and nothing needs to be done here.
    N)maxlen	itertoolsislicecycle)r   r   
max_colorss      r   r   r      s7      ZV-J	 7DDDs   AAA
Ac                z    t        |       }t        j                  dd|      D cg c]
  } ||       c}S c c}w )zGet colors from colormap.r      )num)_get_cmap_instancenplinspace)r   r   cmapr,   s       r   r   r      s3    
 h'D!#Qz!BC#DICCCs   8c                r    t        | t              r&| }t        j                  |    } | t	        d| d      | S )z$Get instance of matplotlib colormap.z	Colormap z is not recognized)r   strmpl	colormaps
ValueError)r   r0   s     r   r-   r-      s?    (C ==*y.@ABBOr   c                    t        |       dk(  rt        d|        t        |       rt        t        |       } | gS t        t
        t           |       } t        t        |             S )z!Get colors from user input color.r   zInvalid color argument: )r%   r5   _is_single_colorr   Colorr   r   !_gen_list_of_colors_from_iterabler   s    r   r!   r!      s_     5zQ3E7;<<UE"wE"E*E1%899r   c                T    t        | t              rt        |       ryt        |       ryy)a0  Check if `color` is a single color, not a sequence of colors.

    Single color is of these kinds:
        - Named color "red", "C0", "firebrick"
        - Alias "g"
        - Sequence of floats, such as (0.1, 0.2, 0.3) or (0.1, 0.2, 0.3, 0.4).

    See Also
    --------
    _is_single_string_color
    TF)r   r2   _is_single_string_color_is_floats_colorr:   s    r   r7   r7      s'     %"9%"@r   c              #  T   K   | D ]  }t        |      r| t        d|        yw)zS
    Yield colors from string of several letters or from collection of colors.
    zInvalid color N)r7   r5   )r   xs     r   r9   r9      s6       3AG~aS122	3s   &(c                    t        t        |       xr2 t        |       dk(  xs t        |       dk(  xr t        d | D                    S )zACheck if color comprises a sequence of floats representing color.      c              3  H   K   | ]  }t        |t        t        f        y w)N)r   intfloat).0r?   s     r   	<genexpr>z#_is_floats_color.<locals>.<genexpr>   s     ;
1sEl+;s    ")boolr
   r%   allr:   s    r   r=   r=      sG    U 	<Z1_/E
a	<;U;; r   c                X    | dk(  rt        |      S | dk(  rt        |      S t        d      )z&Get colors from user input color type.defaultrandomz/color_type must be either 'default' or 'random')_get_default_colors_get_random_colorsr5   )r   r   s     r   r"   r"      s4    Y":..	x	!*--JKKr   c                `    ddl m} |j                  d   D cg c]  }|d   	 }}|d|  S c c}w )z=Get `num_colors` of default colors from matplotlib rc params.r   Nzaxes.prop_cycler   )matplotlib.pyplotpyplotrcParams)r   pltcr   s       r   rM   rM      s9    #"%,,/@"ABQajBFB!J Cs   +c                P    t        |       D cg c]  }t        |       c}S c c}w )z"Get `num_colors` of random colors.)range_random_color)r   r,   s     r   rN   rN      s     */
*;<3M#<<<s   #c                j    t        j                  |       }|j                  d      j                         S )z4Get a random color represented as a list of length 3rA   )comrandom_staterandtolist)columnrss     r   rW   rW      s+     
		&	!B771:r   c                    t         j                  j                         }	 |j                  |        y# t        $ r Y yw xY w)a  Check if `color` is a single string color.

    Examples of single string colors:
        - 'r'
        - 'g'
        - 'red'
        - 'green'
        - 'C3'
        - 'firebrick'

    Parameters
    ----------
    color : Color
        Color string or sequence of floats.

    Returns
    -------
    bool
        True if `color` looks like a valid color.
        False otherwise.
    TF)
matplotlibr   ColorConverterto_rgbar5   )r   convs     r   r<   r<      sD    , ++-D 	U   s   2 	>>)NrK   N)r   rD   r   zColormap | Noner   r2   r   z3dict[str, Color] | Color | Collection[Color] | None)
r   z Color | Collection[Color] | Noner   zstr | Colormap | Noner   r2   r   rD   returnlist[Color])r   re   r   rD   rd   Iterator[Color])r   str | Colormapr   rD   rd   re   )r   rg   rd   r   )r   Color | Collection[Color]rd   re   )r   rh   rd   rH   )r   zCollection[Color]rd   rf   )r   r2   r   rD   rd   re   )r   rD   rd   re   )r]   rD   rd   zlist[float])r   r8   rd   rH   ))
__future__r   collections.abcr   r   r&   typingr   r   r   r`   r3   matplotlib.colorsnumpyr.   pandas._typingr   r8   pandas.util._exceptionsr	   pandas.core.dtypes.commonr
   pandas.core.commoncorecommonrY   r   r   r   r   r   r-   r!   r7   r9   r=   r"   rM   rN   rW   r<    r   r   <module>ru      s   "      3 4 2    *
 !%AE	0>0>0> 0> ?	0>f1N+1N $1N 	1N
 1N 1NhEDDD D:$::,3L =
r   