Custom Color Palette

Description

Allows for the construction of custom (named) color palettes with a fixed set of colors based on hex color inputs (or named matplotlib colors).

Usage

palette(colors, name=None, n=7)

Arguments

colorsstr, list, colorspace.colorlib.colorobject, LinearSegmentedColormap
One or multiple colors which will make up the custom palette, or a matplotlib.colors.LinearSegmentedColormap.
namestr
Name of this custom palette. Defaults to "user_palette". Used for object representation/visualization.
nint
int (>1), number of colors drawn from an hclpalette object. Only taken into account if the object provided on colors inherits from colorspace.palettes.hclpalette.

Return

An object of class colorspace.palettes.palette.

Methods

palette.cmap(continuous=True)
Create Matplotlib Compatible Color Map
palette.colors(*args, **kwargs)
Get Palette Colors
palette.hclplot(**kwargs)
Palette Plot in HCL Space
palette.name()
Get Palette Name
palette.rename(name)
Rename Custom Palette
palette.specplot(*args, **kwargs)
Color Spectrum Plot
palette.swatchplot(**kwargs)
Palette Swatch Plot

Examples

from colorspace.palettes import palette
colors = ["#070707", "#690056", "#C30E62", "#ED8353", "#FDF5EB"]
custom_pal = palette(colors, "test palette")
custom_pal
Palette Name: test palette
       Type: Custom palette
       Number of colors: 5
# Creating custom palettes based on different input
# types (str, list, colorobject)
from colorspace.colorlib import hexcols
from colorspace import palette
hexcols = hexcols(colors)

# Creating a series of custom palette objects
pal1 = palette("#ff0033") # unnamed
pal2 = palette("#ff0033", name = "Custom Palette")
pal3 = palette(colors,  name = "Custom Palette #3")
pal4 = palette(hexcols, name = "Custom Palette #4")
print(pal1)
Palette Name: None
       Type: Custom palette
       Number of colors: 1
print(pal2)
Palette Name: Custom Palette
       Type: Custom palette
       Number of colors: 1
print(pal3)
Palette Name: Custom Palette #3
       Type: Custom palette
       Number of colors: 5
print(pal4)
Palette Name: Custom Palette #4
       Type: Custom palette
       Number of colors: 5
# Palette Swatch Plot
from colorspace import swatchplot
swatchplot([pal3, pal4], figsize = (5.5, 2.0));

Raises

  • TypeError: If n is not int.
  • ValueError: If n is < 2.
  • TypeError: If name is neither str nor None.