"""Plot colors===========.. moduleauthor:: Benjamin Ye <GitHub: @bbye98>This module provides functions to select colors for plots."""importcolorsysfromtypingimportUnionimportmatplotlib.colorsasmc
[docs]defadjust_lightness(colors:Union[str,tuple[float],list[Union[str,tuple[float]]]],amount:float)->Union[tuple[float],list[tuple[float]]]:""" Adjusts the lightness of colors. Parameters ---------- color : `str`, `tuple`, or `list`. The colors to adjust. A single color can be specified as a tuple of normalized RGB values or a string containing its name or a hexadecimal value. Multiple colors can be provided in a `list`. **Examples**: :code:`"aquamarine"`, :code:`"#080085"`, :code:`(0.269, 0.269, 0.269)`. amount : `float` The amount to adjust the luminosity by. A value betwen :math:`0` and :math:`1` darkens the color, while a value greater than :math:`1` lightens the color. Returns ------- colors : `tuple` or `list` The adjusted colors. """ifisinstance(colors,list):fori,colorinenumerate(colors):colors[i]=adjust_lightness(color,amount)returncolorscolors=colorsys.rgb_to_hls(*mc.to_rgb(mc.cnames[colors]ifcolorsinmc.cnameselsecolors))returncolorsys.hls_to_rgb(colors[0],max(0,min(1,amount*colors[1])),colors[2])