![colorconverter matplotlib colorconverter matplotlib](https://cdn-ak.f.st-hatena.com/images/fotolife/m/magattaca/20190127/20190127103859.png)
The scaled lightness should be between 0 and 1, where 1 < scale increases the lightness and 0 ≤ scale < 1 darkens the color. t_hls_values() takes a color as RGB-Tuple, HEX or HTML-name and lets you manipulate the hue, lightness and saturation. There is a Seaborn method, that easily lets you manipulate the lightness. For more details have a look at the old example. Return colorsys.hls_to_rgb(h, min(1, l * scale_l), s = s)Ī simple demonstration. # manipulate h, l, s values and return as rgb This method scales the lightness of an rgb color import colorsys If you still want the option to pass non rgb values like colornames or HEX you can simply use _rgb("#ff0000").
#Colorconverter matplotlib code
Using only colorsys which is part of the python standard library it is possible to scale the lighntess with just two lines of code Return colorsys.hls_to_rgb(c, max(0, min(1, amount * c)), c) Plt.plot(xs, -xs**2, color=lighten_color('b', 1.6), lw=3)Įdit 2: Removed un-needed numpy dependency in the function.Įdit 3: Function modified with improvements from def adjust_lightness(color, amount=0.5):
![colorconverter matplotlib colorconverter matplotlib](https://i.stack.imgur.com/cUfxD.png)
Return colorsys.hls_to_rgb(c, 1 - amount * (1 - c), c)ĮDIT: Indeed, it does darken as well as lighten: import matplotlib.pyplot as plt Input can be matplotlib color string, hex string, or RGB tuple. Lightens the given color by multiplying (1-luminosity) by the given amount. I think setting an amount > 1 might darken too. Here is a function from my gist to lighten any color that I think will work with any color format known to matplotlib.