matplotlib
¶tool for analyzing and creating colormaps: viscm
tool for colorspace conversions: colorspacious
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['figure.figsize'] = 10, 2
import colorspacious
def show_colormap_with_lightness(cmap, colors=256, ax=None):
cmap = plt.cm.get_cmap(cmap)
C = np.arange(colors)
rgb = cmap(C)[:, :3] # ignore alpha values
cam02ucs = colorspacious.cspace_convert(rgb, "sRGB1", "CAM02-UCS")
lightness, chroma, hue = cam02ucs.T
X = np.arange(len(C) + 1)
Y = np.array([0, 100])
xmiddle = X[:-1] + np.diff(X) / 2
if ax is None:
ax = plt.gca()
ax.pcolormesh(X, Y, C.reshape(1, -1), cmap=cmap, rasterized=True)
ax.plot(xmiddle, lightness, '-w', xmiddle, lightness, '--k')
ax.axis([0, colors, 0, 100])
ax.tick_params(axis='x', bottom=False, top=False, labelbottom=False)
ax.set_title(cmap.name)
ax.set_ylabel("CAM02-UCS Lightness")
For most (all?) of matplotlib
's colormaps, there is also a reversed version.
Just append "_r
" to the name of the colormap.
The cividis
colormap is available since matplotlib 2.2.
It further improves on viridis
with regards to color blindness.
See Nuñez et al. (2018), "Optimizing colormaps with consideration for color vision deficiency to enable accurate interpretation of scientific data", https://doi.org/10.1371/journal.pone.0199239.
show_colormap_with_lightness('cividis')
The next 4 colormaps have been introduced in matplotlib 1.5, viridis
is the default colormap since matplotlib 2.0.
Have a look at the webpage documenting the colormap contest and watch this video for details: How We Designed Matplotlib's New Default Colormap (and You Can Too).
show_colormap_with_lightness('viridis')
show_colormap_with_lightness('plasma')
show_colormap_with_lightness('magma')
show_colormap_with_lightness('inferno')
show_colormap_with_lightness('cubehelix')
show_colormap_with_lightness('gist_earth')
show_colormap_with_lightness('gnuplot2')
show_colormap_with_lightness('CMRmap')
show_colormap_with_lightness('copper')
show_colormap_with_lightness('gist_heat')
show_colormap_with_lightness('hot')
show_colormap_with_lightness('afmhot')
show_colormap_with_lightness('autumn')
show_colormap_with_lightness('pink')
show_colormap_with_lightness('bone')
show_colormap_with_lightness('gray')
show_colormap_with_lightness('binary_r')
show_colormap_with_lightness('gist_gray')
show_colormap_with_lightness('gist_yarg_r')
show_colormap_with_lightness('Greys_r')
show_colormap_with_lightness('Blues')
show_colormap_with_lightness('Greens')
show_colormap_with_lightness('Oranges')
show_colormap_with_lightness('Reds')
show_colormap_with_lightness('Purples')
show_colormap_with_lightness('Wistia')
show_colormap_with_lightness('GnBu')
show_colormap_with_lightness('BuGn')
show_colormap_with_lightness('PuBu')
show_colormap_with_lightness('BuPu')
show_colormap_with_lightness('PuRd')
show_colormap_with_lightness('RdPu')
show_colormap_with_lightness('OrRd')
show_colormap_with_lightness('YlGn')
show_colormap_with_lightness('YlGnBu')
show_colormap_with_lightness('PuBuGn')
show_colormap_with_lightness('YlOrBr')
show_colormap_with_lightness('YlOrRd')
show_colormap_with_lightness('coolwarm')
show_colormap_with_lightness('RdBu_r')
show_colormap_with_lightness('turbo')
show_colormap_with_lightness('bwr')
show_colormap_with_lightness('seismic')
show_colormap_with_lightness('RdYlBu_r')
show_colormap_with_lightness('Spectral_r')
show_colormap_with_lightness('RdGy_r')
show_colormap_with_lightness('RdYlGn_r')
show_colormap_with_lightness('BrBG')
show_colormap_with_lightness('PRGn')
show_colormap_with_lightness('PiYG')
show_colormap_with_lightness('PuOr')
show_colormap_with_lightness('rainbow')
show_colormap_with_lightness('jet')
show_colormap_with_lightness('hsv')
show_colormap_with_lightness('gist_rainbow')
show_colormap_with_lightness('gist_ncar')
show_colormap_with_lightness('nipy_spectral')
show_colormap_with_lightness('Set1')
show_colormap_with_lightness('terrain')
show_colormap_with_lightness('gist_stern')
show_colormap_with_lightness('gnuplot')
show_colormap_with_lightness('cool')
show_colormap_with_lightness('spring')
show_colormap_with_lightness('summer')
show_colormap_with_lightness('winter')
show_colormap_with_lightness('brg')
show_colormap_with_lightness('ocean')
show_colormap_with_lightness('Dark2')
show_colormap_with_lightness('Pastel1')
show_colormap_with_lightness('Pastel2')
show_colormap_with_lightness('Set2')
show_colormap_with_lightness('Set3')
show_colormap_with_lightness('Paired')
show_colormap_with_lightness('Accent')
show_colormap_with_lightness('flag')
show_colormap_with_lightness('prism')
Blog post series "Subtleties of Color": part1, part2, part3, part4, part5, part6.
matplotlib colormaps for oceanography: cmocean
How Bad Is Your Colormap? (Or, Why People Hate Jet – and You Should Too)
Why Should Engineers and Scientists Be Worried About Color?
Somewhere Over the Rainbow: How to Make Effective Use of Colors in Meteorological Visualizations
The end of the rainbow: An open letter to the climate science community
perceptual rainbow:
https://mycarta.wordpress.com/2012/05/29/the-rainbow-is-dead-long-live-the-rainbow-series-outline/
https://mycarta.wordpress.com/2013/02/21/perceptual-rainbow-palette-the-method/
https://mycarta.wordpress.com/color-palettes/
http://nbviewer.ipython.org/urls/dl.dropbox.com/s/5t9jrhr7va3wscj/colors.ipynb
http://nbviewer.ipython.org/github/kwinkunks/notebooks/blob/master/Matteo_colourmaps.ipynb
Blog posts about the new colormap for MATLAB®, named "parula": part1, part2, part3, part4.
"turbo" colormap:
https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html
https://github.com/matplotlib/matplotlib/issues/15091
https://github.com/matplotlib/matplotlib/pull/15275
"rainforest" colormap:
https://e13tools.readthedocs.io/en/latest/user/colormaps.html#rainforest
https://github.com/matplotlib/matplotlib/issues/14668