o
    Û­j°   ã                   @  s2  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  mZ erMd dlmZ 				d<d=dd„Zd>dd„Zd?dd„Zd@dd „ZdAd"d#„ZdBd%d&„Z dCd(d)„Z!dDd+d,„Z"dCd-d.„Z#dEd/d0„Z$dFd1d2„Z%dFd3d4„Z&dGd7d8„Z'dHd:d;„Z(dS )Ié    )Úannotations)Ú
CollectionÚIteratorN)ÚTYPE_CHECKINGÚcast)ÚMatplotlibColor)Úfind_stack_level)Úis_list_like)ÚColormapÚdefaultÚ
num_colorsÚintÚcolormapúColormap | NoneÚ
color_typeÚstrÚcolorú3dict[str, Color] | Color | Collection[Color] | Nonec                 C  s.   t |tƒr|S t|||| d�}tt|| d�ƒ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.
    ©r   r   r   r   ©r   )Ú
isinstanceÚdictÚ_derive_colorsÚlistÚ_cycle_colors)r   r   r   r   Úcolors© r   ú^/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/style.pyÚget_standard_colors   s   
&ür   ú Color | Collection[Color] | Noneústr | Colormap | NoneÚreturnúlist[Color]c                 C  sP   | du r|durt ||d�S | dur"|durtjdtƒ d� t| ƒS t||d�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.
    Nr   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   r   r   r   r   P   s   'þr   r   úIterator[Color]c                 c  s,   � t |t| ƒƒ}t t | ¡|¡E dH  dS )zÈCycle 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_colorsr   r   r   r   „   s   €r   ústr | Colormapc                   s&   t | ƒ‰ ‡ fdd„tjdd|d�D ƒS )zGet colors from colormap.c                   s   g | ]}ˆ |ƒ‘qS r   r   ©Ú.0Únum©Úcmapr   r   Ú
<listcomp>”   ó    z-_get_colors_from_colormap.<locals>.<listcomp>r   é   )r3   )Ú_get_cmap_instanceÚnpÚlinspace)r   r   r   r4   r   r$   Ž   s   r$   r
   c                 C  s4   t | tƒr| }tj|  } | du rtd|› d�ƒ‚| S )z$Get instance of matplotlib colormap.Nz	Colormap z is not recognized)r   r   ÚmplÚ	colormapsÚ
ValueError)r   r5   r   r   r   r9   —   s   

r9   úColor | Collection[Color]c                 C  sL   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+   r>   Ú_is_single_colorr   ÚColorr   r   Ú!_gen_list_of_colors_from_iterable©r   r   r   r   r'   ¡   s   
r'   Úboolc                 C  s&   t | tƒrt| ƒrdS t| ƒrdS dS )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   r   Ú_is_single_string_colorÚ_is_floats_colorrC   r   r   r   r@   °   s
   r@   úCollection[Color]c                 c  s,   � | D ]}t |ƒr|V  qtd|› �ƒ‚dS )zS
    Yield colors from string of several letters or from collection of colors.
    zInvalid color N)r@   r>   )r   Úxr   r   r   rB   Æ   s   €ürB   c                 C  s6   t t| ƒot| ƒdkpt| ƒdkotdd„ | D ƒƒƒS )zACheck if color comprises a sequence of floats representing color.é   é   c                 s  s   � | ]
}t |ttfƒV  qd S )N)r   r   Úfloat)r2   rH   r   r   r   Ú	<genexpr>Ö   s   € z#_is_floats_color.<locals>.<genexpr>)rD   r	   r+   ÚallrC   r   r   r   rF   Ñ   s   ÿýrF   c                 C  s(   | dkrt |ƒS | dkrt|ƒS tdƒ‚)z&Get colors from user input color type.r   Úrandomz/color_type must be either 'default' or 'random')Ú_get_default_colorsÚ_get_random_colorsr>   )r   r   r   r   r   r(   Ú   s
   r(   c                 C  s,   ddl m} dd„ |jd D ƒ}|d| … S )z=Get `num_colors` of default colors from matplotlib rc params.r   Nc                 S  s   g | ]}|d  ‘qS rC   r   )r2   Úcr   r   r   r6   è   r7   z'_get_default_colors.<locals>.<listcomp>zaxes.prop_cycle)Úmatplotlib.pyplotÚpyplotÚrcParams)r   Úpltr   r   r   r   rO   ä   s   rO   c                 C  s   dd„ t | ƒD ƒS )z"Get `num_colors` of random colors.c                 S  s   g | ]}t |ƒ‘qS r   )Ú_random_colorr1   r   r   r   r6   î   r7   z&_get_random_colors.<locals>.<listcomp>)Úranger   r   r   r   rP   ì   s   rP   Úcolumnúlist[float]c                 C  s   t  | ¡}| d¡ ¡ S )z4Get a random color represented as a list of length 3rI   )ÚcomÚrandom_stateÚrandÚtolist)rX   Úrsr   r   r   rV   ñ   s   
rV   rA   c                 C  s0   t j ¡ }z| | ¡ W dS  ty   Y dS 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.
    FT)Ú
matplotlibr   ÚColorConverterÚto_rgbar>   )r   Úconvr   r   r   rE   ø   s   
ýÿrE   )Nr   N)r   r   r   r   r   r   r   r   )
r   r   r   r    r   r   r   r   r!   r"   )r   r"   r   r   r!   r)   )r   r0   r   r   r!   r"   )r   r0   r!   r
   )r   r?   r!   r"   )r   r?   r!   rD   )r   rG   r!   r)   )r   r   r   r   r!   r"   )r   r   r!   r"   )rX   r   r!   rY   )r   rA   r!   rD   ))Ú
__future__r   Úcollections.abcr   r   r,   Útypingr   r   r%   r_   r<   Úmatplotlib.colorsÚnumpyr:   Úpandas._typingr   rA   Úpandas.util._exceptionsr   Úpandas.core.dtypes.commonr	   Úpandas.core.commonÚcoreÚcommonrZ   r
   r   r   r   r$   r9   r'   r@   rB   rF   r(   rO   rP   rV   rE   r   r   r   r   Ú<module>   s>    ü
3
4


	





	



