A story on how to plot topographic data intuitively and easily understandable also for non-scientists and people with color vision deficiency (CVD): Just because you find it pretty, it's not necessarily pretty through everyone's eyes.

I had recently a couple of vivid discussions on twitter concerning perceptually linear colormaps, color vision deficiency and topographic maps. Jet, Roy G. Biv, or sometimes simply called rainbow are all very similar colormaps that still dominate many presentations of science. I reckon many scientist find it beautiful and use it because i) it's colorful and ii) that's the default colormap and why questioning anything that is accepted as standard.

Roy G. Biv, Jet and rainbow in it's full beauty...

The problem is that they are not perceptually linear, meaning that it introduces steps in your data that are actually not there. It jumps through different colors and brightness and gives you the impression that these jumps also exist in you data - dangerous. In 2015 Matplotlib developers came up with some great alternatives called viridis, inferno, magma and plasma which they nicely summarized on the SciPy conference. The message was clear: Everybody should use linear colormaps. And, in fact, many people developed new ones to fit their data (e.g. cmocean). 3 years later Nunez et al. pulished a paper where they turned the matplotlib default colormap viridis into a colormap that looks basically the same for CVD eyes and called it cividis.

Cividis - a CVD-safe colormap

Cividis was promoted by an article in Scientific American that used topographic maps of mars as a counter example that a rainbow colormap is a bad choice not just for non-scientists. I believe the creator of these maps joined the discussion

And me: challenge accepted.

I picked a region on the Moon that on Earth would span from the southern tip of Chile to the Carribeans and as far west as Samoa in the central tropical Pacific. Pretending to be a scientist that never heard of perceptually linear colormaps, I plotted the geoid of the moon with a rainbow colormap. An astrophysicist would see this as impact craters and probably would also, thanks to the colorbar, notice that the geoid forms a high plateau in the top left and something like a valley in the bottom left.

The geoid of moon as seen with a rainbow colormap

Producing the same plot with magma (on the left) or cividis (on the right) solves the problem of CVD, however, it still requires the reader to associate a bright yellow with something that is higher up and a dark blue with something that is further down.

Looking at any kind of real topography (and this could even mean your neighbours roof) your eye together with your brain is able to translate a signal of brightness determined by highlights and shades into a 3D surface. Can we make use of this feature of the human brain to better visualize topographic data? Mathematically, instead of plotting the height of the geoid as above, we plot one component of the gradient of that surface with a greyscale colormap.

The gradient of the geoid visualized with a greyscale

Imagine you walk on the surface of the moon. The focus is now on steep ascents and descents, one visualized as a bright highlight and the other one as a dark shade. Your brain naturally turns that greyscale image into a map of mountains, hills, ridges, valleys and trenches. You can even see that the top right is clearly a smoother surface and presumably more comfortable to walk on than rough region in the top left.

Using another component of the gradient would simply move around your light source, such that highlights become shades and vice versa. Although we are clearly able to count all the impact craters on Moon now, it is hard for us to decide whether a crater is in a valley or on the aforementioned plateau. It seems that in order to reverse the operation of the gradient your brain would need to integrate the highlights and shades across the whole map - however it only does that only locally. Question therefore: Can we combine information of brightness which clearly emphasizes the structure of topography with color to also provide the information of the actual height?

The idea is simple: The color represents the height and the brightness is added on top visualizing the gradient of the height. Let's do that for magma and also for cividis.

One problem remains: A concave object with light from one side can also be a convex object with light from the other side. Hence, an impact crater might look like a little hill to others. The colormap hopefully supports the impact crater to be perceived as an impact crater and solves the ambiguity of it being upgraded to a hill.

Ready for the bigger picture? Let us zoom out and switch to the actual topography of Moon and Mars. Left cividis, right thermal from cmocean.

Moon and Mars topography

Thanks Mark for this challenge. I definitely learned a lot and keen on applying this technique for the visualization of geophysical turbulence! You can find further example figures and the python scripts in this github repository.