U
    ¿mœdÔ  ã                   @  sˆ  d dl mZ d dlZd dlmZmZ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.œ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Ú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   úZ/home/sam/Atlas/atlas_env/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   N   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  s4   t | tƒr0| }tj|  } | dk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   r0   •   s    

r0   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%   r3   Ú_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_colorr7   r   r   r   r4   ®   s
    r4   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)r4   r3   )r   Úxr   r   r   r6   Ä   s    r6   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>)r8   r	   r%   Úallr7   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_colorsr3   )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 r7   r   )r*   Úcr   r   r   r.   æ   s     z'_get_default_colors.<locals>.<listcomp>zaxes.prop_cycle)Zmatplotlib.pyplotZpyplotZrcParams)r   Zpltr   r   r   r   rB   â   s    rB   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.   ì   s     z&_get_random_colors.<locals>.<listcomp>)Úranger   r   r   r   rC   ê   s    rC   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)rG   Úrsr   r   r   rE   ï   s    
rE   r5   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_rgbar3   )r   Úconvr   r   r   r9   ö   s    
r9   )Nr   N)(Ú
__future__r   r&   Útypingr   r   r   r   r    rK   r2   Zmatplotlib.colorsÚnumpyr1   Zpandas._typingr   r5   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr	   Zpandas.core.commonÚcoreÚcommonrH   r
   r   r   r   r   r0   r"   r4   r6   r:   r#   rB   rC   rE   r9   r   r   r   r   Ú<module>   s:      ü34
	
	
