Skip to content

Usage

Creating a TastyMap

Creating a TastyMap is as simple as passing a list of named colors:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])

image

You may also use hex colors, RGB tuples, and HSV tuples:

from tastymap import cook_tmap

tmap = cook_tmap(["#ff0000", "#00ff00", "#0000ff"])

Or even registered colormaps with customizations:

from tastymap import cook_tmap

tmap = cook_tmap("RdBu_r", num_colors=11)

image

Using a TastyMap

After you have a TastyMap, you can use it in your plots by passing a name:

from tastymap import cook_tmap
import matplotlib.pyplot as plt
import numpy as np

tmap = cook_tmap("RdBu_r", num_colors=11, name="RdBu_r_11")

data = np.random.rand(10, 10)
plt.imshow(data, cmap='RdBu_r_11')
plt.colorbar()

matplotlib

Or if you don't want to name it, you can access the underlying LinearSegmentedColormap object:

from tastymap import cook_tmap
import matplotlib.pyplot as plt
import numpy as np

tmap = cook_tmap("RdBu_r", num_colors=11)
cmap = tmap.cmap

data = np.random.rand(10, 10)
plt.imshow(data, cmap=cmap)
plt.colorbar()

If you want better control over the bounds, ticks, and labels of the resulting colorbar, you can use the pair_tbar function:

from tastymap import cook_tmap, pair_tbar
import matplotlib.pyplot as plt
import numpy as np

tmap = cook_tmap("RdBu_r", num_colors=11)

data = np.random.rand(10, 10)
img = plt.imshow(data)
pair_tbar(img, tmap, bounds=[0, 0.18, 1], labels=["zero", ".18", "one"], uniform_spacing=True)

pair_mpl

You can also use it with HoloViews / hvPlot:

from tastymap import cook_tmap, pair_tbar
import holoviews as hv
import numpy as np

hv.extension('bokeh')

tmap = cook_tmap("RdBu_r", num_colors=4)

data = np.random.rand(10, 10)
img = hv.Image(data)
pair_tbar(img, tmap, bounds=[0, 0.2, 0.5, 0.7, 1], uniform_spacing=True)

pair hv

Customizing a TastyMap

You can customize a TastyMap by passing in some or all of these keyword arguments:

from tastymap import cook_tmap

cook_tmap(
    colors_or_cmap=["red", "green", "blue"],
    num_colors=18,
    reverse=True,
    hue=1.28,
    saturation=0.5,
    value=1.18,
    bad="gray",
    under="red",
    over="blue",
    name="custom_rgb_18",
)

image

Or, you can use the methods on the TastyMap object:

from tastymap import cook_tmap

tmap = (
    cook_tmap(["red", "green", "blue"])
    .resize(18)
    .reverse.tweak_hsv(1.28, 0.5, 1.18)
    .set_extremes("gray", "red", "blue")
    .register("custom_rgb_18")
)

Getting the color palette

You can get the color palette as an array of hex colors:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
colors = tmap.to_model("hex")
array(['#ff0000', '#008000', '#0000ff'], dtype='<U7')

Or a list of RGB and HSV tuples:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
colors = tmap.to_model("rgb")
array([[1.        , 0.        , 0.        ],
       [0.        , 0.50196078, 0.        ],
       [0.        , 0.        , 1.        ]])

Joining two TastyMaps

You can combine two TastyMaps with &:

from tastymap import cook_tmap

tmap1 = cook_tmap(["red", "green", "blue"])
tmap2 = cook_tmap(["yellow", "cyan", "magenta"])

tmap = tmap1 & tmap2

image

Tweaking with operators

You can tweak the hue by adding or subtracting:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
tmap + 10 - 5

You can tweak the saturation by multiplying or dividing:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
tmap * 0.5 / 0.25

You can tweak the brightness value by exponentiating:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
tmap ** 2

You can reverse the order of the colors with ~:

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
~tmap

You can rename a TastyMap with << (input):

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
tmap << "rgb"

You can register a TastyMap with >> (output):

from tastymap import cook_tmap

tmap = cook_tmap(["red", "green", "blue"])
tmap >> "rgb"

Suggesting based on a description

You can have AI suggest a TastyMap based on a description:

from tastymap import ai

tmap = ai.suggest_tmap("Pikachu")

image

Using the TastyKitchen UI

You can use the TastyKitchen UI to craft your TastyMap interactively:

tastymap ui

tastykitchen

Be sure to first install tastymap with the ui extra:

pip install tastymap[ui]