Create Hex Color Object

Description

Creates a color object using hex colors (str). Can be converted to all other color spaces: CIELAB, CIELUV, CIEXYZ, HLS, HSV, RGB, polarLAB, polarLUV, and sRGB.

Usage

hexcols(hex_)

Arguments

hex_str, list of str, numpy.ndarray of type str
Hex colors. Only six and eight digit hex colors are allowed (e.g., #000000 or #00000050 if with alpha channel). If invalid hex colors are provided the object will raise an exception. Invalid hex colors will be handled as numpy.nan.

Methods

hexcols.colors(fixup=True, rev=False)
Extract Hex Colors
hexcols.dropalpha()
Remove Alpha Channel
hexcols.get(dimname=None)
Extracting Color Coordinates
hexcols.get_whitepoint()
Get White Point
hexcols.hasalpha()
Check for Alpha Channel
hexcols.hclplot(**kwargs)
Palette Plot in HCL Space
hexcols.length()
Get Number of Colors
hexcols.set(**kwargs)
Set Coordinates/Manipulate Colors
hexcols.set_whitepoint(**kwargs)
Set White Point
hexcols.specplot(**kwargs)
Color Spectrum Plot
hexcols.swatchplot(**kwargs)
Palette Swatch Plot
hexcols.to(to, fixup=True)
Transform Color Space

Examples

from colorspace import hexcols
# Creating hex color object from string
hexcols("#cecece")
  • #CECECE
# Creating hex color object from list of strings
hexcols(["#ff0000", "#00ff00"])
  • #FF0000
  • #00FF00
# Creating hex colors via numpy array
from numpy import asarray
cols = hexcols(asarray(["#ff000030", "#00ff0030", 
                        "#FFFFFF", "#000"]))
cols
  • #FF000030
  • #00FF0030
  • #FFFFFF
  • #000000
# Convert hex colors to another color space (CIEXYZ)
cols.to("CIEXYZ")
cols
CIEXYZ color object (4 colors)
            X       Y       Z   alpha
  1:    41.25   21.27    1.93    0.19
        35.76   71.52   11.92    0.19
        95.05  100.00  108.88     ---
         0.00    0.00    0.00     ---
# Picking 7 hex colors from the Green-Orange
# diverging palette for demonstrating standard representation
# in jupyter engine and standard print.
from colorspace import diverging_hcl
cols2 = hexcols(diverging_hcl("Green-Orange")(7))
cols2 # jupyter HTML representation
  • #11C638
  • #77D17F
  • #B0DAB3
  • #E2E2E2
  • #EDC9B0
  • #F1B077
  • #EF9708
print(cols2) # default representation
hexcols color object (7 colors)
         hex_
  1: b'#11C638'
     b'#77D17F'
     b'#B0DAB3'
     b'#E2E2E2'
     b'#EDC9B0'
     b'#F1B077'
     b'#EF9708'