a
    é´«j°   ã                   @  s�  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ršd dlmZ d>d
ddddœdd„Zdddd
ddœdd„Zdd
ddœdd„Zdd
ddœdd„Zddd œd!d"„Zd#dd$œd%d&„Z d#d'd$œd(d)„Z!d*dd$œd+d,„Z"d#d'd$œd-d.„Z#dd
dd/œd0d1„Z$d
dd2œd3d4„Z%d
dd2œd5d6„Z&d
d7d8œd9d:„Z'd;d'd$œd<d=„Z(dS )?é    )Úannotations)Ú
CollectionÚIteratorN)ÚTYPE_CHECKINGÚcast)ÚMatplotlibColor)Úfind_stack_level)Úis_list_like)ÚColormapÚdefaultÚintzColormap | NoneÚstrz3dict[str, Color] | Color | Collection[Color] | None)Ú
num_colorsÚcolormapÚ
color_typeÚcolorc                 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/laksyashrimp/venv/lib/python3.9/site-packages/pandas/plotting/_matplotlib/style.pyÚget_standard_colors   s    &
ür   z Color | Collection[Color] | Nonezstr | Colormap | Nonezlist[Color])r   r   r   r   Úreturnc                 C  sT   | du r|durt ||d�S | durD|dur<tjdtƒ d� t| ƒS t||d�S 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   zIterator[Color])r   r   r   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   Z
max_colorsr   r   r   r   „   s    r   zstr | Colormap)r   r   r   c                   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   é   )r+   )Ú_get_cmap_instanceÚnpZlinspace)r   r   r   r,   r   r   Ž   s    r   r
   )r   r   c                 C  s4   t | tƒr0| }tj|  } | du r0td|› d�ƒ‚| S )z$Get instance of matplotlib colormap.Nz	Colormap z is not recognized)r   r   ÚmplZ	colormapsÚ
ValueError)r   r-   r   r   r   r1   —   s    

r1   zColor | Collection[Color])r   r   c                 C  sL   t | ƒdkrtd| › �ƒ‚t| ƒr2tt| ƒ} | gS ttt | ƒ} tt| ƒƒS )z!Get colors from user input color.r   zInvalid color argument: )r%   r4   Ú_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_colorr8   r   r   r   r5   °   s
    r5   zCollection[Color]c                 c  s,   | D ]"}t |ƒr|V  qtd|› �ƒ‚qdS )zS
    Yield colors from string of several letters or from collection of colors.
    zInvalid color N)r5   r4   )r   Úxr   r   r   r7   Æ   s    r7   c                 C  s6   t t| ƒo2t| ƒdks"t| ƒdko2t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)r*   r<   r   r   r   Ú	<genexpr>Ö   r/   z#_is_floats_color.<locals>.<genexpr>)r9   r	   r%   Úallr8   r   r   r   r;   Ñ   s    ÿýr;   )r   r   r   c                 C  s,   | dkrt |ƒS | dkr t|ƒS tdƒ‚dS )z&Get colors from user input color type.r   Úrandomz/color_type must be either 'default' or 'random'N)Ú_get_default_colorsÚ_get_random_colorsr4   )r   r   r   r   r   r#   Ú   s
    r#   )r   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 r8   r   )r*   Úcr   r   r   r.   è   r/   z'_get_default_colors.<locals>.<listcomp>zaxes.prop_cycle)Zmatplotlib.pyplotZpyplotZrcParams)r   Zpltr   r   r   r   rC   ä   s    rC   c                 C  s   dd„ t | ƒD ƒS )z"Get `num_colors` of random colors.c                 S  s   g | ]}t |ƒ‘qS r   )Ú_random_colorr)   r   r   r   r.   î   r/   z&_get_random_colors.<locals>.<listcomp>)Úranger   r   r   r   rD   ì   s    rD   zlist[float])Úcolumnr   c                 C  s   t  | ¡}| d¡ ¡ S )z4Get a random color represented as a list of length 3r=   )ÚcomZrandom_stateZrandÚtolist)rH   Úrsr   r   r   rF   ñ   s    
rF   r6   c                 C  s6   t j ¡ }z| | ¡ W n ty,   Y dS 0 dS dS )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.
    FTN)Ú
matplotlibr   ZColorConverterZto_rgbar4   )r   Úconvr   r   r   r:   ø   s    
r:   )Nr   N))Ú
__future__r   Úcollections.abcr   r   r&   Útypingr   r   r    rL   r3   Zmatplotlib.colorsÚnumpyr2   Zpandas._typingr   r6   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr	   Zpandas.core.commonÚcoreÚcommonrI   r
   r   r   r   r   r1   r"   r5   r7   r;   r#   rC   rD   rF   r:   r   r   r   r   Ú<module>   s<      ü34
	
	
