a
    k=ic                      @  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rd 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   r/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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   U   s    'r   zIterator[Color])r   r   r   c                 c  s*   t |t| }tt| |E dH  dS )zCycle 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  sF   t | trB| }t r tj|  } n
t| } | du 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   r3      s    

r3   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'   r7   _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   r8      s
    r8   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)r8   r7   )r   xr   r   r   r:      s    r:   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>   r1   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_colorsr7   )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      r1   z'_get_default_colors.<locals>.<listcomp>zaxes.prop_cycle)Zmatplotlib.pyplotZpyplotZrcParams)r   Zpltr   r   r   r   rF      s    rF   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      r1   z&_get_random_colors.<locals>.<listcomp>)ranger   r   r   r   rG      s    rG   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)rK   rsr   r   r   rI      s    
rI   r9   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_rgbar7   )r   convr   r   r   r=      s    
r=   )Nr   N).
__future__r   r(   typingr   r   r   r   r   r   r"   rO   r5   Zmatplotlib.cmr6   Zmatplotlib.colorsnumpyr4   Zpandas.util._exceptionsr	   Zpandas.core.dtypes.commonr
   Zpandas.core.commoncorecommonrL   Z"pandas.plotting._matplotlib.compatr   r   r   rB   r9   r   r   r   r!   r3   r$   r8   r:   r>   r%   rF   rG   rI   r=   r   r   r   r   <module>   s>       34
		
