1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
U
¬ý°dæ ã@sˆddlmZddlZddlmZmZmZmZddlZddl    Z
ddl Z    ddl Z ddlmZddlmZddlmZddlmmZer’ddl mZd=d    d
d d d œdd„Zddd d    ddœdd„Zdd    ddœdd„Zdd    ddœdd„Zdddœd d!„Zd"dd#œd$d%„Zd"d&d#œd'd(„Z d)dd#œd*d+„Z!d"d&d#œd,d-„Z"d d    dd.œd/d0„Z#d    dd1œd2d3„Z$d    dd1œd4d5„Z%d    d6d7œd8d9„Z&d:d&d#œd;d<„Z'dS)>é)Ú annotationsN)Ú TYPE_CHECKINGÚ
CollectionÚIteratorÚcast)ÚMatplotlibColor)Úfind_stack_level)Ú is_list_like)ÚColormapÚdefaultÚintzColormap | NoneÚstrz3dict[str, Color] | Color | Collection[Color] | None)Ú
num_colorsÚcolormapÚ
color_typeÚcolorcCs.t|tƒr|St||||d}tt||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.
    ©rrrr©r)Ú
isinstanceÚdictÚ_derive_colorsÚlistÚ _cycle_colors)rrrrÚcolors©rúXd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/plotting/_matplotlib/style.pyÚget_standard_colorss&
ürz Color | Collection[Color] | Nonezstr | Colormap | Nonez list[Color])rrrrÚreturncCsT|dkr|dk    rt||dS|dk    rD|dk    r<tjdtƒdt|ƒSt||dSdS)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.
    NrzC'color' and 'colormap' cannot be used simultaneously. Using 'color')Ú
stacklevel)Ú_get_colors_from_colormapÚwarningsÚwarnrÚ_get_colors_from_colorÚ_get_colors_from_color_typerrrrrNs' þrzIterator[Color])rrrccs*t|t|ƒƒ}t t |¡|¡EdHdS)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)rrZ
max_colorsrrrr‚srzstr | Colormap)rrrcs&t|ƒ‰‡fdd„tjdd|dDƒS)zGet colors from colormap.csg|] }ˆ|ƒ‘qSrr©Ú.0Únum©ÚcmaprrÚ
<listcomp>’sz-_get_colors_from_colormap.<locals>.<listcomp>ré)r+)Ú_get_cmap_instanceÚnpZlinspace)rrrr,rrŒsrr
)rrcCs4t|tƒr0|}tj|}|dkr0td|›dƒ‚|S)z$Get instance of matplotlib colormap.Nz    Colormap z is not recognized)rr ÚmplZ    colormapsÚ
ValueError)rr-rrrr0•s 
 
r0zColor | Collection[Color])rrcCsLt|ƒdkrtd|›ƒ‚t|ƒr2tt|ƒ}|gSttt|ƒ}tt|ƒƒS)z!Get colors from user input color.rzInvalid color argument: )r%r3Ú_is_single_colorrÚColorrrÚ!_gen_list_of_colors_from_iterable©rrrrr"Ÿs 
r"ÚboolcCs&t|tƒrt|ƒrdSt|ƒr"dSdS)a0Check 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)rr Ú_is_single_string_colorÚ_is_floats_colorr7rrrr4®s
r4zCollection[Color]ccs,|D]"}t|ƒr|Vqtd|›ƒ‚qdS)zS
    Yield colors from string of several letters or from collection of colors.
    zInvalid color N)r4r3)rÚxrrrr6Äsr6cCs6tt|ƒo2t|ƒdks"t|ƒdko2tdd„|DƒƒƒS)zACheck if color comprises a sequence of floats representing color.éécss|]}t|ttfƒVqdS)N)rr Úfloat)r*r;rrrÚ    <genexpr>Ôsz#_is_floats_color.<locals>.<genexpr>)r8r    r%Úallr7rrrr:Ïs ÿýr:)rrrcCs,|dkrt|ƒS|dkr t|ƒStdƒ‚dS)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)rrrrrr#Øs
r#)rrcCs,ddlm}dd„|jdDƒ}|d|…S)z=Get `num_colors` of default colors from matplotlib rc params.rNcSsg|] }|d‘qSr7r)r*Úcrrrr.æsz'_get_default_colors.<locals>.<listcomp>zaxes.prop_cycle)Zmatplotlib.pyplotZpyplotZrcParams)rZpltrrrrrBâs rBcCsdd„t|ƒDƒS)z"Get `num_colors` of random colors.cSsg|] }t|ƒ‘qSr)Ú _random_colorr)rrrr.ìsz&_get_random_colors.<locals>.<listcomp>)ÚrangerrrrrCêsrCz list[float])ÚcolumnrcCst |¡}| d¡ ¡S)z4Get a random color represented as a list of length 3r<)ÚcomZ random_stateZrandÚtolist)rGÚrsrrrrEïs
rEr5cCs8tj ¡}z| |¡Wntk
r.YdSXdSdS)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)Ú
matplotlibrZColorConverterZto_rgbar3)rÚconvrrrr9ös 
r9)Nr N)(Ú
__future__rr&Útypingrrrrr rKr2Zmatplotlib.colorsÚnumpyr1Zpandas._typingrr5Zpandas.util._exceptionsrZpandas.core.dtypes.commonr    Zpandas.core.commonÚcoreÚcommonrHr
rrrrr0r"r4r6r:r#rBrCrEr9rrrrÚ<module>s:     ü34