gL i LddlmZddlmZmZddlZddlmZmZddl Z ddl Z ddl Z ddl ZddlmZddlmZddlmZddlmcmZerddl mZ d dd Z dd Zdd Z dd Zdd Z ddZ ddZ!ddZ"ddZ#d dZ$d!dZ%d!dZ&d"dZ'd#dZ(y)$) annotations) CollectionIteratorN) TYPE_CHECKINGcast)MatplotlibColor)find_stack_level) is_list_like)Colormapcpt|tr|St||||}tt ||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. colorcolormap color_type num_colorsr) isinstancedict_derive_colorslist _cycle_colors)rrrrcolorss g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/plotting/_matplotlib/style.pyget_standard_colorsrs>L%  F  f< ==c|| t||S|,|tjdtt |St ||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. rzC'color' and 'colormap' cannot be used simultaneously. Using 'color') stacklevel)_get_colors_from_colormapwarningswarnr _get_colors_from_color_get_colors_from_color_typer s rrrPsWN }-(jII     MMU+- &e,,*:*MMrc#Kt|t|}tjtj||Ed{y7w)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)maxlen itertoolsislicecycle)rr max_colorss rrrs7 ZV-J  7DDDsAA A A czt|}tjdd|Dcgc] }|| c}Scc}w)zGet colors from colormap.r)num)_get_cmap_instancenplinspace)rrcmapr,s rrrs3 h 'D!#Qz!B C#DI CC Cs8crt|tr&|}tj|}|t d|d|S)z$Get instance of matplotlib colormap.z Colormap z is not recognized)rstrmpl colormaps ValueError)rr0s rr-r-s?(C ==*  y.@AB B Orct|dk(rtd|t|rtt|}|gStt t|}t t|S)z!Get colors from user input color.rzInvalid color argument: )r%r5_is_single_colorrColorrr!_gen_list_of_colors_from_iterablers rr!r!s_ 5zQ3E7;<<UE"w E"E *E 1%8 99rcTt|tr t|ryt|ryy)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)rr2_is_single_string_color_is_floats_colorr:s rr7r7s'%"9%"@ rc#TK|D]}t|r|td|yw)zS Yield colors from string of several letters or from collection of colors. zInvalid color N)r7r5)rxs rr9r9s63 A G~aS12 2 3s&(ctt|xr2t|dk(xst|dk(xrtd|DS)zACheck if color comprises a sequence of floats representing color.c3HK|]}t|ttfyw)N)rintfloat).0r?s r z#_is_floats_color..s; 1sEl+;s ")boolr r%allr:s rr=r=sG U < Z1_ /E a < ;U; ; rcX|dk(r t|S|dk(r t|Std)z&Get colors from user input color type.defaultrandomz/color_type must be either 'default' or 'random')_get_default_colors_get_random_colorsr5)rrs rr"r"s4Y":.. x !*--JKKrc`ddlm}|jdDcgc]}|d }}|d|Scc}w)z=Get `num_colors` of default colors from matplotlib rc params.rNzaxes.prop_cycler)matplotlib.pyplotpyplotrcParams)rpltcrs rrMrMs9#"%,,/@"A BQaj BF B !J Cs +cPt|Dcgc] }t|c}Scc}w)z"Get `num_colors` of random colors.)range _random_color)rr,s rrNrNs */ *; <3M#  << >)NrKN)rrDrzColormap | Nonerr2rz3dict[str, Color] | Color | Collection[Color] | None) rz Color | Collection[Color] | Nonerzstr | Colormap | Nonerr2rrDreturn list[Color])rrerrDrdIterator[Color])rstr | ColormaprrDrdre)rrgrdr )rColor | Collection[Color]rdre)rrhrdrH)rzCollection[Color]rdrf)rr2rrDrdre)rrDrdre)r]rDrdz list[float])rr8rdrH)) __future__rcollections.abcrrr&typingrrrr`r3matplotlib.colorsnumpyr.pandas._typingrr8pandas.util._exceptionsr pandas.core.dtypes.commonr pandas.core.commoncorecommonrYr rrrrr-r!r7r9r=r"rMrNrWr<rrrus"342 * !%AE 0>0>0>0> ? 0>f1N +1N$1N 1N  1N  1NhEDDDD : $ : :,3L = r