U
    ÎZj‘   ã                   @  s¬  d dl mZ d dlZd dlmZmZmZmZmZm	Z	 d dl
Z
d dlZd dlmZ d dlZd dlZd dlmZ d dlmZ d dlm  mZ d dlmZ er¦d dlmZ eeee f 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.œd/d0„Z)d	dd1œd2d3„Z*d	dd1œd4d5„Z+d	d6d7œd8d9„Z,d:d&d#œd;d<„Z-dS )>é    )ÚannotationsN)ÚTYPE_CHECKINGÚ
CollectionÚIteratorÚSequenceÚUnionÚcast)Úfind_stack_level)Úis_list_like)Úmpl_ge_3_6_0)Ú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   úd/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/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kr|dk	rt ||d�S | dk	rD|dk	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   U   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>™   s     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  sF   t | tƒrB| }tƒ r tj|  } n
t | ¡} | dkrBtd|› d�ƒ‚| S )z$Get instance of matplotlib colormap.Nz	Colormap z is not recognized)r   r   r   ÚmplZ	colormapsÚcmZget_cmapÚ
ValueError)r   r/   r   r   r   r2   œ   s    

r2   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'   r6   Ú_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_colorr:   r   r   r   r7   ¸   s
    r7   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)r7   r6   )r   Úxr   r   r   r9   Î   s    r9   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>Þ   s     z#_is_floats_color.<locals>.<genexpr>)r;   r
   r'   Úallr:   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_colorsr6   )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 r:   r   )r,   Úcr   r   r   r0   ð   s     z'_get_default_colors.<locals>.<listcomp>zaxes.prop_cycle)Zmatplotlib.pyplotZpyplotZrcParams)r   Zpltr   r   r   r   rE   ì   s    rE   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   r0   ö   s     z&_get_random_colors.<locals>.<listcomp>)Úranger   r   r   r   rF   ô   s    rF   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)rJ   Úrsr   r   r   rH   ù   s    
rH   r8   c                 C  s8   t j ¡ }z| | ¡ W n tk
r.   Y dS X 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_rgbar6   )r   Úconvr   r   r   r<      s    
r<   )Nr   N).Ú
__future__r   r(   Útypingr   r   r   r   r   r   r"   rN   r4   Zmatplotlib.cmr5   Zmatplotlib.colorsÚnumpyr3   Zpandas.util._exceptionsr	   Zpandas.core.dtypes.commonr
   Zpandas.core.commonÚcoreÚcommonrK   Z"pandas.plotting._matplotlib.compatr   r   r   rA   r8   r   r   r   r!   r2   r$   r7   r9   r=   r%   rE   rF   rH   r<   r   r   r   r   Ú<module>   s>       ü34
		
