Fork me on GitHub

Meeting Summary

Color and colormaps in matplotlib

We informally discussed various aspects of color and colormaps in matplotlib. Some of the topics included:

  • Color and colormap basics
  • Generating custom diverging colors
  • Centering colormaps and displaying the center-valued color
  • Differences between pcolormesh and contourf
  • Setting upper, lower limits, and bad colors
  • Using a colormap to color lines

After the meeting, I created a notebook expanding on many of the examples that were shown. The notebook may be found in the How-to section and has been added to the notebook repository on GitHub.

The problem with jet

We also talked about the disadvantages of the jet colormap that is the default for matplotlib and Matlab (pre-2014b). The main disadvantage of the jet colormap is that there are discontinuities in the luminosity (lightness) of the map. Because of these kinks in lightness and non-ordered colors, figures using the jet colormap often seem to have details that aren't in the data, for example, bands existing in smoothly-varying data around yellow. Worse yet, jet can also obscure details in green and cyan bands because the lightness doesn't change as rapidly in these regions. So jet both obscures features and generates false features. For examples of this, see some of the references below.

Basic colormap theory

What is needed instead is a perceptual colormap, i.e. one in which equal steps in data are perceived as equal steps in the colorspace. Because humans perceive changes in lightness more readily than changes in hue, colormaps with monotonically and evenly increasing lightness are easier to interpret. jet does not fit this category.

Colormaps can generally be split into 4 groups:

  • Sequential: Lightness increases/decreases monotonically, often from white through a single hue. Good for showing magnitude and ordering of data. Generally converts to grayscale well.
  • Diverging: Lightness has a maximum at some central or critical value, and reaches a minimum at either end. Good for showing anomalies about zero or some other critical value as well as direction. Usually does not convert well to grayscale because the two ends often have similar luminosity.
  • Qualitative: These colormaps represent categorical data that may not have an ordering and are often discrete. For these mappings, it is important that all the colors are distinguishable from all the others.
  • Special / Miscellaneous: These are maps that may or may not fit the above categories and usually consist of maps designed for a particular use such as showing both land and water topography or displaying hot/cold regions. These colormaps try to connect with intuitive colors for the parameters and, while they may not be perfect perceptual maps, are useful for some purposes where nature suggests a colormap.

Other important considerations when designing colormaps include awareness of colorblindness, conversion to grayscale, and how the colors look when used in different media such as online, print, and projection.

Colormap references

During the meeting, we compiled a number of useful colormap references, both from online and published literature:

matplotlib references

  • Choosing colormaps Guide: Good guide on choosing colormaps provided by the matplotlib team. Has plots of the various default colormaps show how lightness changes throughout the maps
  • Default colormaps: Quick reference for all of the default colormaps in matplotlib.

Webpages

  • Colorbrewer: Good source for colormaps. Shows example maps applying the colormap in different regions. Also gives color-blind and printer-safe options.
  • Palletton and Adobe Color CC: Online utilities for generating custom color schemes that follow established color paradigms.
  • How bad is your colormap?: Quick and recent overview of problems with the jet colormap along with some Python code (and a haiku!).
  • The Rainbow is Dead. Long live the Rainbow!: Long series examining the jet colormap, how to make it better, and looking at different colorspaces for interpolation.

Publications

Comments