Colormaps¶
This section shows the different colormaps that are available in datachart
module. The colormaps are used to customize the colors of the charts.
All colormaps are available via the datachart.constants.COLORS constant.
In [1]:
Copied!
from typing import List, Tuple
import numpy as np
import matplotlib.pyplot as plt
from typing import List, Tuple
import numpy as np
import matplotlib.pyplot as plt
In [2]:
Copied!
from datachart.constants import COLORS
from datachart.utils.colors import get_colormap
from datachart.constants import COLORS
from datachart.utils.colors import get_colormap
In [3]:
Copied!
def plot_color_gradients(cmap_list: List[Tuple[str, str]], n_sections: int = 256):
"""Plots the gradients of multiple colormaps.
Args:
cmap_list (List[Tuple[str, str]]): The list of colormaps to plot.
n_sections (int, optional): The number of sections to plot. Defaults to 256.
"""
gradient = np.linspace(0, 1, n_sections)
gradient = np.vstack((gradient, gradient))
# Create figure and adjust figure height to number of colormaps
nrows = len(cmap_list)
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(8.2, figh))
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.2, right=0.99)
axs[0].set_title(f"datachart colormaps", fontsize=14)
for ax, (name, value) in zip(axs, cmap_list):
ax.imshow(gradient, aspect="auto", cmap=get_colormap(value))
ax.text(
-0.01,
0.5,
name,
va="center",
ha="right",
fontsize=10,
transform=ax.transAxes,
)
# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axs:
ax.set_axis_off()
def plot_color_gradients(cmap_list: List[Tuple[str, str]], n_sections: int = 256):
"""Plots the gradients of multiple colormaps.
Args:
cmap_list (List[Tuple[str, str]]): The list of colormaps to plot.
n_sections (int, optional): The number of sections to plot. Defaults to 256.
"""
gradient = np.linspace(0, 1, n_sections)
gradient = np.vstack((gradient, gradient))
# Create figure and adjust figure height to number of colormaps
nrows = len(cmap_list)
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(8.2, figh))
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.2, right=0.99)
axs[0].set_title(f"datachart colormaps", fontsize=14)
for ax, (name, value) in zip(axs, cmap_list):
ax.imshow(gradient, aspect="auto", cmap=get_colormap(value))
ax.text(
-0.01,
0.5,
name,
va="center",
ha="right",
fontsize=10,
transform=ax.transAxes,
)
# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axs:
ax.set_axis_off()
In [4]:
Copied!
cmap_list = [
("COLORS.Blue", COLORS.Blue),
("COLORS.Green", COLORS.Green),
("COLORS.Orange", COLORS.Orange),
("COLORS.Purple", COLORS.Purple),
("COLORS.Grey", COLORS.Grey),
("COLORS.YlGnBu", COLORS.YlGnBu),
("COLORS.YlGn", COLORS.YlGn),
("COLORS.BuGn", COLORS.BuGn),
("COLORS.GnBu", COLORS.GnBu),
("COLORS.PuBu", COLORS.PuBu),
("COLORS.RdBn", COLORS.RdBn),
("COLORS.RdYlBu", COLORS.RdYlBu),
("COLORS.BrGn", COLORS.BrGn),
("COLORS.PuGn", COLORS.PuGn),
("COLORS.OrPu", COLORS.OrPu),
("COLORS.RdGy", COLORS.RdGy),
("COLORS.RdYlGn", COLORS.RdYlGn),
("COLORS.Spectral", COLORS.Spectral),
("COLORS.MixedLight", COLORS.MixedLight),
("COLORS.MixedDark", COLORS.MixedDark),
]
cmap_list = [
("COLORS.Blue", COLORS.Blue),
("COLORS.Green", COLORS.Green),
("COLORS.Orange", COLORS.Orange),
("COLORS.Purple", COLORS.Purple),
("COLORS.Grey", COLORS.Grey),
("COLORS.YlGnBu", COLORS.YlGnBu),
("COLORS.YlGn", COLORS.YlGn),
("COLORS.BuGn", COLORS.BuGn),
("COLORS.GnBu", COLORS.GnBu),
("COLORS.PuBu", COLORS.PuBu),
("COLORS.RdBn", COLORS.RdBn),
("COLORS.RdYlBu", COLORS.RdYlBu),
("COLORS.BrGn", COLORS.BrGn),
("COLORS.PuGn", COLORS.PuGn),
("COLORS.OrPu", COLORS.OrPu),
("COLORS.RdGy", COLORS.RdGy),
("COLORS.RdYlGn", COLORS.RdYlGn),
("COLORS.Spectral", COLORS.Spectral),
("COLORS.MixedLight", COLORS.MixedLight),
("COLORS.MixedDark", COLORS.MixedDark),
]
Continuous scales
In [5]:
Copied!
plot_color_gradients(cmap_list=cmap_list)
plot_color_gradients(cmap_list=cmap_list)
Discrete scales
In [6]:
Copied!
# change the number of sections `n_sections`
plot_color_gradients(cmap_list=cmap_list, n_sections=10)
# change the number of sections `n_sections`
plot_color_gradients(cmap_list=cmap_list, n_sections=10)