API Reference

Color spaces

The colorspace package supports the following color spaces (see also Color Spaces: Classes and Utilities). These classes all inherit from one superclass colorobject which provides a series of useful methods.

Class Description
polarLUV, HCL Create polarLUV (=HCL) colors
CIELUV Create CIELUV colors
CIELAB Create CIELAB colors
CIEXYZ Create CIEXYZ colors
RGB Create RGB colors
sRGB Create sRGB colors
HLS Create HLS colors
HSV Create HSV colors
hexcols Create hex colors
Method Description
.to() Convert colors between color spaces
.colors() Extract HEX colors
.hclplot() Palette plot in HCL space
.specplot() Color spectrum plot
.swatchplot() Palette swatch plot

HCL-based palettes

colorspace comes with a variety of pre-defined palettes (see hcl_palettes and HCL-Based Color Palettes) which can either be used as is, or customized. In addition, fully customized palettes can be created/defined. All classes inherit from the superclass hclpalette providing the same functionality. The main methods are listed below.

Class Description
qualitative_hcl Qualitative HCL Color Palettes
sequential_hcl Sequential HCL Color Palettes
diverging_hcl Diverging HCL Color Palettes
rainbow_hcl HCL Based Rainbow Palette
heat_hcl HCL Based Heat Color Palette
terrain_hcl HCL Based Terrain Color Palette
diverging_hsv Diverging HCL Color Palettes
Method Description
.colors() Draw colors from the palette
.cmap() Create matplotlib compatible colormap
.hclplot() Palette plot in HCL space
.specplot() Color spectrum plot
.swatchplot() Palette swatch plot
.show_settings() Show palette settings (trajectory definition)

Custom palettes

Besides HCL-based color palettes which are defined by their trajectories trough the HCL space (see HCL-Based Color Palettes: Construction Details), colorspace provides the palette class to set up custom palettes based on a fixed number of colors, providing similar functionality as the HCL-based palettes. The main methods are listed below.

Class Description
palette Create custom color palette
Method Description
.colors() Draw colors from the palette
.cmap() Create matplotlib compatible colormap
.hclplot() Palette plot in HCL space
.specplot() Color spectrum plot
.swatchplot() Palette swatch plot
.show_settings() Show palette settings (trajectory definition)

Palette visualization and assessment

To visually assess sets of colors (or color palettes), colorspace provides a series of plotting function. These are also interfaced by the identically named methods of the different palette classes listed above.

Function Description
swatchplot Palette Swatch Plot
specplot Color Spectrum Plot
demoplot Create Demo Plots
hclplot Palette Plot in HCL Space

GUI for choosing color palettes

choose_palette Graphical User Interface for Choosing HCL Color Palettes

Color vision defficiency emulation

deutan, protan, tritan Simulate Color Vision Deficiency
cvd_image Check Images for Color Constraints

Color manipulation and utilities

Function Description
desaturate Desaturate Colors by Chroma Removal in HCL Space
max_chroma Compute Maximum Chroma for Given Hue and Luminance in HCL
contrast_ratio W3C Contrast Ratio
compare_colors Compare colors/check for equality
check_hex_colors Checking HEX Color Validity
lighten, darken Algorithmically Lighten or Darken Colors
mixcolor Compute the Convex Combination of Two Colors
extract_transparency, adjust_transparency Adjust or Extract Transparency of Colors