In [1]:
Copied!
from chromatic import one2another, version
from chromatic import one2another, version
In [2]:
Copied!
version()
version()
Out[2]:
'0.4.12'
How do we make a new colormap?¶
All we need to specify is the color at the bottom and the color at the top. If we want to get really fancy, we can specify different alpha
(= opacity) values for either of these limits.
In [3]:
Copied!
one2another("orchid", "black")
one2another("orchid", "black")
Out[3]:
orchid2black
under
bad
over
In [4]:
Copied!
one2another("black", "orchid")
one2another("black", "orchid")
Out[4]:
black2orchid
under
bad
over
In [5]:
Copied!
one2another(bottom="orchid", top="orchid", alpha_bottom=0)
one2another(bottom="orchid", top="orchid", alpha_bottom=0)
Out[5]:
orchid2orchid
under
bad
over
That's it! You can use these colormaps anywhere you'd set cmap=
in a matplotlib
function.
In [6]:
Copied!
import numpy as np, matplotlib.pyplot as plt
# make a custom cmap
my_fancy_cmap = one2another("orchid", "black")
# make some fake data
x, y = np.random.uniform(-1, 1, [2, 1000])
z = np.random.normal(0, 1, [10, 10])
# use the cmap
fi, ax = plt.subplots(1, 2, constrained_layout=True)
ax[0].scatter(x, y, c=x**2 + y**2, cmap=my_fancy_cmap)
ax[0].axis("scaled")
ax[1].imshow(z, cmap=my_fancy_cmap)
ax[1].axis("scaled");
import numpy as np, matplotlib.pyplot as plt
# make a custom cmap
my_fancy_cmap = one2another("orchid", "black")
# make some fake data
x, y = np.random.uniform(-1, 1, [2, 1000])
z = np.random.normal(0, 1, [10, 10])
# use the cmap
fi, ax = plt.subplots(1, 2, constrained_layout=True)
ax[0].scatter(x, y, c=x**2 + y**2, cmap=my_fancy_cmap)
ax[0].axis("scaled")
ax[1].imshow(z, cmap=my_fancy_cmap)
ax[1].axis("scaled");