Pre-Defined HCL Palettes

Description

Function to retrieve and/or display pre-defined color palettes based on the HCL (Hue-Chroma-Luminance) color model, excludes ‘diverging xtra’ (see divergingx_palettes).

The inputs type_ and name can be used to retrieve a custom subset, custom can be used to add custom palettes if if needed.

If plot = True, **kwargs can be used to specify the figure size of the resulting image by specifying figsize = (height, width) where both, height and width must be int/float, specifying the height and width in inches. Note that matplotlib must be installed when plot = True.

Usage

hcl_palettes(n=5, type_=None, name=None, plot=False,
custom=None, ncol=4, **kwargs)

Arguments

nint
The number of colors to be plotted, defaults to 7. Only used if plot = True.
type_None, str, list
Given a str or a list of str, only a subset of all available default color maps will returned/displayed. Can be used in combination with input argument name. Uses partial matching, not case sensitive.
nameNone, str, list
Similar to type_. If not specified all palettes will be returned. Can be set to a str or a list of str containing the names of the palettes which should be returned/plotted.
plotbool
If False (default) an object of type hclpalettes is returned, containing the (subset) of pre-defined HCL color palettes.
customdefaultpalette
One or multiple defaultpalettes can be provided in addition.
ncolint
Positive int, number of columns, defaults to 4.
**kwargs
Forwarded to the main swatchplot function if plot = True.

Return

Object of type hclpalettes or a matplotlib.figure.Figure object. If plot = True a plot will be created and the figure handler returned. If plot = False (default) an object of class hclpalettes is returned.

Examples

## Basic usage:

from colorspace import hcl_palettes
# Get all pre-defined HCL palettes shipped with the package
hcl_palettes()
HCL palettes

Type:  Basic: Sequential (single-hue)
Names: Grays, Light Grays, Blues 2, Purples 2, Reds 2
       Greens 2

Type:  Basic: Sequential (multi-hue)
Names: Purple-Blue, Red-Purple, Red-Blue, Purple-Orange
       Blue-Yellow, Green-Yellow, Red-Yellow, Heat, Heat 2
       Terrain, Terrain 2, Viridis, Plasma, Dark Mint, Mint
       Emrld, BluYl, ag_GrnYl, Peach, PinkYl

Type:  Basic: Qualitative
Names: Pastel 1, Dark 2, Dark 3, Set 2, Set 3, Warm, Cold
       Harmonic, Dynamic

Type:  Basic: Diverging
Names: Blue-Red, Blue-Red 2, Blue-Yellow 2, Blue-Yellow 3
       Green-Orange, Cyan-Magenta, Tropic

Type:  Advanced: Sequential (single-hue)
Names: Blues 3, Purples 3, Reds 3, Greens 3, Oslo

Type:  Advanced: Sequential (multi-hue)
Names: Purple-Yellow, Inferno, Rocket, Mako, BluGrn, Teal
       TealGrn, Burg, BurgYl, RedOr, OrYel, Purp, PurpOr
       Sunset, Magenta, SunsetDark, ag_Sunset, BrwnYl, YlOrRd
       YlOrBr, OrRd, Oranges, YlGn, YlGnBu, Reds, RdPu, PuRd
       Purples, PuBuGn, PuBu, Greens, BuGn, GnBu, BuPu, Blues
       Lajolla, Turku, Hawaii, Batlow

Type:  Advanced: Diverging
Names: Blue-Red 3, Red-Green, Purple-Green, Purple-Brown
       Green-Brown, Broc, Cork, Vik, Berlin, Lisbon, Tofino
# Get all diverging HCL palettes (basic and advanced)
hcl_palettes(type_ = "Diverging")
HCL palettes

Type:  Basic: Diverging
Names: Blue-Red, Blue-Red 2, Blue-Yellow 2, Blue-Yellow 3
       Green-Orange, Cyan-Magenta, Tropic

Type:  Advanced: Diverging
Names: Blue-Red 3, Red-Green, Purple-Green, Purple-Brown
       Green-Brown, Broc, Cork, Vik, Berlin, Lisbon, Tofino
# Get only basic diverging HCL palettes
hcl_palettes(type_ = "Basic: Diverging")
HCL palettes

Type:  Basic: Diverging
Names: Blue-Red, Blue-Red 2, Blue-Yellow 2, Blue-Yellow 3
       Green-Orange, Cyan-Magenta, Tropic
# Get specific HCL palettes by name
hcl_palettes(name = ["Oranges", "Tropic"]) 
HCL palettes

Type:  Basic: Diverging
Names: Tropic

Type:  Advanced: Sequential (multi-hue)
Names: Oranges
# Visualize all diverging HCL palettes
hcl_palettes(type_ = "Diverging", ncol = 2,
             plot = True, figsize = (6, 4));

# Visualize specific palettes selected by name
hcl_palettes(name = ["Oranges", "Tropic"],
             plot = True, ncol = 1, figsize = (6, 2));

# Specify number of colors shown
hcl_palettes(n = 5,  type_ = "Basic: Diverging",
             plot = True, ncol = 1, figsize = (6, 3));

hcl_palettes(n = 51, type_ = "Advanced: Diverging",
             plot = True, ncol = 1, figsize = (6, 8));

# Extract specific palettes after loading
palettes = hcl_palettes()
c1 = palettes.get_palette("Oranges")
c1
Palette Name: Oranges
        Type: Advanced: Sequential (multi-hue)
        Inspired by: ...
         c1            70
         c2            10
         cmax         150
         fixup       True
         gui            0
         h1            20
         h2            55
         l1            30
         l2            97
         p1           1.2
         p2           1.3
c2 = palettes.get_palette("Greens")
c2
Palette Name: Greens
        Type: Advanced: Sequential (multi-hue)
        Inspired by: ...
         c1            35
         c2             5
         cmax          70
         fixup       True
         gui            1
         h1           135
         h2           115
         l1            25
         l2            98
         p1           1.0
         p2           1.5
# Modify palettes by overwriting palette settings
c1.set(h1 = 99, l2 = 30, l1 = 30)
c1.rename("Custom Palette #1")
c2.set(h1 = -30, l1 = 40, l2 = 30, c1 = 30, c2 = 40)
c2.rename("Custom Palette #2")

# Visualize customized palettes
hcl_palettes(type_ = "Custom", custom = [c1, c2],
             plot = True, ncol = 1, figsize = (6, 1));

Raises

  • TypeError: If n/ncol not of type int.
  • TypeError: If type_ is not None or str.
  • TypeError: If not is bool plot.
  • TypeError: In case custom is an invalid input.
  • ValueError: If n or ncol are not positive.
  • Exception: If no palettes can be found matching the type_ argument.