Fixing non-uniform colormaps with fixthejet
Why (and how) to avoid perceptually non-uniform colormaps during data visualization
-by Krishna Rao
Information is not knowledge.
Information can be converted into knowledge if patterns underlying the information are well understood. In today’s day and age of fast-paced advances in science and technology, one of the key information sources is data. It is hardly surprising then that we produce a lot of it- about 2.5 quintillion bytes every day.
One of the most powerful ways to make sense of scientific data (and thus transform it into knowledge) is by plotting it.
Want to know if human weight is related to height? Plot it!
Want to know whether the expansion of the universe is accelerating? Plot it!
Want to know how hot it gets the farther you go from the equator? Plot it … err carefully!
Although visualizations can be powerful to consume data quickly and derive insights, they can also be harmful if not done right.
In this article we will learn:
- Why be careful with our choice of colormaps?
- Why not to use the “jet” and all other perceptually non-uniform colormaps?
- How to change the colormaps of poorly-made figures using a new python package
The problem with non-uniform colormaps
Look at the above figure of sea surface temperature (SST) and try to summarize it in one sentence. When I showed the above chart to 10 of my friends, seven of them responded with some version of the following, “The temperature decreases as we go away from the equator, with a sudden transition at about 30 degrees north or south” (italics are mine). The reason my friends thought there was a sudden change in temperature was that colors with high luminance (like yellow) stand out in our eyes. In other words, the colormap used above creates artificial contrasts where none exists. The same data in a better colormap (example with “viridis” is shown below) shows that there is no such sudden transition.
We could excuse this if it was a one-off case. Unfortunately, the scientific literature is full of such maps using bad, perceptually non-uniform colormaps like “jet”, “rainbow”, “spectral”, “gist”, etc. To add to the harm, many of these colormaps are also not friendly to colorblind people!
In 2015, many people noticed this phenomenon and nudged their respective communities in R, Python, Matlab, etc. to change their default colormaps to be perceptually uniform so as to not introduce any artificial gradients in luminance. For more information about the update, check out the launch of the new default colormaps in matplotlib in Python. I encourage everyone to use the perceptually-uniform colormaps available to them (they can be found here for Python and R). But that still leaves us with the poorly-created maps from the pre-2015 era. If left unfixed, they can be difficult to cite in posters or presentations. To date, they continue to appear in top conferences, journals, and reports. How can we continue to use the knowledge from the “jet” era, but avoid the pitfalls associated with interpreting them?
fixthejet is a python package that can transform an image (.jpg/.png) from “jet” colormap to any other colormap based on user input. The script selectively changes jet colors only. All other colors in the image remain unchanged. Thus, the background and text of images are left unchanged (provided, they are visibly different than colors in "jet"). Since the package requires only an image file, the time and effort required to obtain the raw data underlying the image is avoided.
Changing the colormaps of poorly-made images by others is now as simple as entering this in the terminal:
Here are two examples showing how the package can transform images from “jet” colormap to perceptually-uniform colormaps.
Use --colormap <output colormap> to control the colormap of outfile. Default is "viridis". Only Matplotlib colormaps are supported.
Interested in using fixthejet? Here are the downloading instructions.
Using bad colormaps like "jet" can lead to artificial gradients, which in some cases, can lead to false inferences. Be kind to your audience and avoid non-uniform colormaps like "jet", "rainbow", "spectral", etc.
If you are making your own map, do not use “jet” or other perceptually non-uniform colormaps
If you want to use someone else’s poorly made figure in your presentation, use fixthejet python package to change the colormap and remove any artificially-created patterns