Color maps
plotphotoTom's rainbow color map #
While exploring and analyzing existing color maps in plotting libraries, I observed that a color map can be generated from three mathematical functions that specify an intensity value given the value of a position on a linear subspace, with one function for each of the red, green and blue channels in the RGB color model.
I also observed that a rainbowlike color map can be generated from three curved distributions with a peak near the start, the middle and the end of a linear subspace for red, green and blue respectively, in order or in reversed order.
Therefore, I have created my own rainbowlike color map with three functions that output unnormalized normal distributions with different values of μ and σ for red, green and blue channels.
Note that an unnormalized normal distribution here means that it has a global maximum of 1, while a typical normalized normal distribution has the sum of all values of x being 1.
The proposed color map is hereafter referred to as Tom's rainbow color map. The opportunity to name the color map Tombow is forgone to avoid naming conflict with the existing Japanese stationery brand.
The following code snippet includes my Python function gen_cmap
that returns an nquantized ListedColormap in matplotlib given a list of functions that map a position in a linear space to a color intensity value for each channel. It is used to generate Tom's rainbow color map from an easily configurable set of mathematical functions.
import numpy as np
from matplotlib.colors import ListedColormap
from matplotlib.cm import register_cmap
def gen_cmap(funcs, n=256, **kwargs):
X = np.linspace(0, 1, n)
Y = np.asarray([ list(map(func, X)) for func in funcs ]).T
return ListedColormap(Y, **kwargs)
register_cmap(cmap=gen_cmap([
lambda x: np.exp(0.5 * (x0.75)**2 / 0.25**2),
lambda x: np.exp(0.5 * (x0.5)**2 / 0.25**2),
lambda x: np.exp(0.5 * (x0.2)**2 / 0.35**2),
], name='TomsRainbow'))
Plots for color maps #
Tom's rainbow color map TomsRainbow
can be compared with existing rainbowlike color maps, including rainbow
and turbo
.

TomsRainbow
has darker reds, less purplish blues and smoother intensity changes thanrainbow
. BothTomsRainbow
andrainbow
have lighter colors overall when compared withturbo
andjet
. 
TomsRainbow
has brighter colors especially on both ends and smoother intensity changes thanturbo
.
The use of Tom's rainbow color map is demonstrated in another post that includes contour surface plots of various mathematical functions using my color map.
In the following figure, plots are provided for various color maps including TomsRainbow
and other existing color maps. From left to right:

Surface plot is provided. The equation of the surface plot used is z = (x + y) / 2, where variable x is on the horizontal axis, variable y is on the vertical axis, and variable z is the surface. Undesirable banding effect, if any, can be more easily observable as diagonal lines that are perpendicular to the dashed line in the diagonal plot than in the vertical or horizontal plot of the color map.

A line plot of the brightness levels of the red, green and blue components in the RGB color model is generated. An additional color bar at the bottom of the line plot is provided for reference.

A line plot of the values of the J component (luminance) in the CAM02 Uniform Color Space is generated to show the perceived brightness level.

A line plot of the values of the a* component (redgreen) and the b* component (yellowblue) in the CAM02 Uniform Color Space is generated to show the perceived brightness level.
Mesh plot with color bar and line plot of RGB components of different color maps
External links #

The
turbo
color map introduced in 2019 recently supported in matplotlib is meant to be a substitute for thejet
color map introduced in 1993.turbo
has a higher lightness range than other rainbow color maps. 
The
inferno
,viridis
,plasma
andmagma
color maps are perceptually uniform color maps introduced in 2015 for matplotlib with its viscm tool.inferno
andmagma
have a higher lightness range thanplasma
. 
Other human perception models for designing color maps include colorcet introduced in 2015.

Note that a library colorspacious is used for color space conversion from sRGB1 to CAM02UCS for the plot.
Changelog
 Mar 2021 Added color map generation code snippet with description.
 Feb 2021 Added Tom's Rainbow color map with new plots including line plots of CAM02UCS components in SVG format.
 Jan 2021 Updated plot to include over 30 matplotlib color maps.
 Oct 2020 Added line plots of RGB components for each color map.
 Oct 2020 Reorganized content in bullet points.