to_hex¶
- to_hex(color, space='rgb', cycle=None, keep_alpha=True)[source]¶
Translate the color in any format and from any colorspace to a HEX string. This is a generalization of
matplotlib.colors.to_hex.- Parameters
color (
str,3-tuple, or4-tuple) – The color specification. Can be a tuple of channel values, a hex string, a registered color name, a cycle color like'C0', or a colormap color (seeColorDatabase).If
spaceis'rgb', this is a tuple of RGB values, and if any channels are larger than2, the channels are assumed to be on the0to255scale and are divided by255.space (
{'rgb', 'hsv', 'hcl', 'hpl', 'hsl'}, optional) – The colorspace for the input channel values. Ignored unlesscoloris a tuple of numbers.cycle (
strorlist, optional) – The registered color cycle name used to interpret colors that look like'C0','C1', etc. Default isrc.cycle='colorblind'.keep_alpha (
bool, optional) – Whether to keep the opacity channel. IfTruean 8-digit HEX is returned. Otherwise a 6-digit HEX is returned. Default isTrue.
- Returns
color (
str) – A HEX string.