# Selecting best colormap for Matlab/Matplotlib plots

Much has been written on selecting best colormaps from among:

- sequential
- diverging
- qualitative

## Sequential

Sequential colormaps are good for representing magnitude of data. How much flow, how much precipitation, how much weight, temperature, etc. Having a monotonic lightness factor is important for perceptual consistency.

Non-linear lightness is used to emphasize certain ranges of data, perhaps where snow changes to ice or rain. Non-monotonic lightness can be used to emphasize different types of precipitation or phase changes, etc.

## Reversed colormap

Reversed colormaps are useful for sparse data such as astronomical images or precipitation data where a lot of data is at or near zero relative to other data. The reversal leads to near-zero areas being white and higher intensities being darker. While any colormap can be reversed, typically sequential colormaps are used with/without reversal.

### Matplotlib

Matplotlib colormaps are reversed by appending `_r`

to the colormap name.
For example:

```
cmap='cubehelix_r'
```

### Matlab / Octave

Matlab and GNU Octave colormaps are reversed by `flipud()`

the colormap.
Colormaps in `.m`

code are represented as an (N,3) array, where `N` is the number of steps in the colormap (typically 64 or 256).

```
colormap(flipud(cubehelix()))
```

## Diverging

Diverging colormaps are useful for positive or negative data where the sign is as important as the magnitude. For example, in/out flows, positive/negative charge. These colormaps are white near the zero point (which can be offset) and intensify as their absolute magnitude increases.

## Qualitative

These colormaps emphasize difference between values, but without a particular sense of ordering. This can be useful for categories, say a histogram of salary vs. employee type.

## Notes

- Example sparse data plots with reversed sequential colormaps: colormap_white_min.py, colormap_white_min.m
- Matlab cubehelix.m

## Leave a Comment