Colors¶
artlo
includes a series of color palettes, colormaps and helper functions for working with them. You can find the relevant code documentation below.
Palettes¶
You can access the color palettes via artlo.color.palettes
. This object is a modified dictionary, and you can access the items by indexing (artlo.color.palettes['pastel']
) or as attributes (artlo.color.palettes.vegetation
). These return a list of hex codes for the colors in the palette. You'll typically want these for mapping items with a discrete, known number of colors. Custom color paletters include:
artlo.color.palettes.keys()
>>> dict_keys(['salo', 'cfo', 'bold', 'pastel', 'vegetation', 'wildfire', 'wind', 'weather'])
Colormaps¶
For mapping continuous patterns, or many classes, the above color palettes are also accessible as colormaps. These colormaps interpolate colors between the different palette values, meaning they can be indexed from 0-1 to retrieve the color at the indexed point. You can pass a single value or a list of values to retun as many colors as you need, which are returned as RGBA tuples.
# get the midpoint vegetation color value
artlo.color.cmaps.vegetation(0.5)
>>> (0.699679610406254, 0.7732154299628349, 0.3038831218762014, 1.0)
# get a range of color values
artlo.color.cmaps.vegetation([0.0, 0.5, 1.0])
>>> array([[0.97647059, 0.98039216, 0.89803922, 1. ],
>>> [0.69967961, 0.77321543, 0.30388312, 1. ],
>>> [0.19607843, 0.34901961, 0. , 1. ]])
Support functions¶
You can create your own color map by passing a custom color palette to artlo.color.create_cmap(['list', 'of', 'colors'])
.
Convert between hex/rgba with artlo.color.to_hex(rgba)
or artlo.color.to_rgba(hex)
.
Color reference¶
Continuous color palettes¶
Discrete color palettes¶
The above images are generated by scripts/plot-colormaps.py
.
Code documentation¶
Support for working with colormaps, palettes, and type conversions.
create_cmap(palette, n=None, stops=None, alpha=1.0, name='artlo')
¶
Creates a matplotlib-format linear segmented color map from a list of colors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
palette |
list
|
a list of hex codes or a list of (r,g,b,a) tuples |
required |
stops |
list
|
a list of 0.0-1.0 values mapping each palette entry with it's relative color map location |
None
|
alpha |
float
|
scalar 0-1 float opacity value (transparent-opaque, respectively) |
1.0
|
name |
str
|
the name of the color map |
'artlo'
|
Returns:
Name | Type | Description |
---|---|---|
cmap | a matplotlib colormap. |
Source code in artlo/color.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
to_hex(rgba)
¶
Converts an rgb/rgba color tuple to it's hexadecimal code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba |
tuple
|
an input color (e.g., rgb or rgba list/tuple). |
required |
Returns:
Name | Type | Description |
---|---|---|
hexcode | a hexadecimal string corresponding to the input color. |
Source code in artlo/color.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
to_rgba(hexcode)
¶
Converts a hexadecimal color to a tuple of RGBA values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hexcode |
str
|
a hexadecimal string, e.g. "#000000" for black. |
required |
Returns:
Name | Type | Description |
---|---|---|
rgba | a 4-element list of 0-1 rgba values. |
Source code in artlo/color.py
80 81 82 83 84 85 86 87 88 89 90 91 |
|