Sometimes I want a color just brighter or darker:
def shade_color(hex_color, offset):
new_color = hex_color
if len(hex_color) in [6, 7]:
if hex_color[0] == "#":
hex_color = hex_color[1:]
rgb_hex = np.array([float(int(hex_color[x:x+2], 16)) for x in [0, 2, 4]])
rgb_hex /= 255.0
hls_color = colorsys.rgb_to_hls(*rgb_hex)
new_color = colorsys.hls_to_rgb(hls_color[0], min(1, hls_color[1]*offset), hls_color[2])
return "#" + "".join(['%2s' % (hex(int(i*255))[2:]).rjust(2, '0') for i in new_color])
which you can use as the following:
import matplotlib.pyplot as plt
color = '#62BAAB'
x = np.arange(50)
for offset in np.arange(0.0, 2, 0.02):
plt.plot(x, [offset]*50, color=Plotter.shade_color(color, offset), linewidth=5)
plt.show()