a
    oÝEb�  ã                   @  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mZ d dlZd dlZd dlmZ d dlm  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-d.„Z$ddd/œd0d1„Z%ddd/œd2d3„Z&dd4d5œd6d7„Z'd8d$d!œd9d:„Z(dS )<é    )ÚannotationsN)ÚTYPE_CHECKINGÚ
CollectionÚIteratorÚSequenceÚUnionÚcast)Ú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   úa/home/ja/django-apps/lartica_env/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  sN   | du r|durt ||d�S | dur>|dur6t 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')Ú_get_colors_from_colormapÚwarningsÚwarnÚ_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©r   r   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 | ¡} | du r0td|› d�ƒ‚| S )z$Get instance of matplotlib colormap.Nz	Colormap z is not recognized)r   r   ÚcmZget_cmapÚ
ValueError)r   Zcmapr   r   r   r/   –   s    

r/   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$   r2   Ú_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_colorr6   r   r   r   r3   ¯   s
    r3   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)r3   r2   )r   Úxr   r   r   r5   Å   s    r5   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>)r7   r	   r$   Úallr6   r   r   r   r9   Ð   s    ÿýr9   )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_colorsr2   )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 r6   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   rA   ã   s    rA   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   rB   ë   s    rB   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)rF   Úrsr   r   r   rD   ð   s    
rD   r4   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_rgbar2   )r   Úconvr   r   r   r8   ÷   s    
r8   )Nr   N))Ú
__future__r   r%   Útypingr   r   r   r   r   r   r   Zmatplotlib.cmr1   Zmatplotlib.colorsrJ   Únumpyr0   Zpandas.core.dtypes.commonr	   Zpandas.core.commonÚcoreÚcommonrG   r
   r   r=   r4   r   r   r   r   r/   r!   r3   r5   r9   r"   rA   rB   rD   r8   r   r   r   r   Ú<module>   s8       ü33
	
	
