A good divergent color palette for Matlab

INTRODUCTION

Before starting my series on perceptual color palettes I thought it was worth mentioning an excellent function I found some time ago on the Matlab File Exchange. The function is called Light and Bartlein Color Maps. It was a Matlab Pick of the week, and it can be used to create four color palettes discussed in the EOS paper by Light and Bartlein. Each of these palettes is suited for a specific task, and the authors claim they are non confusing for viewers with color vision deficiencies.

In the remainder of this post I will showcase one of the palettes, called orange-white-purple, as it is good divergent scheme [1]. With the code below I am going to load the World Topography Matlab demo data, create  the palette and use it to display the data.

%% load World Topography Matlab demo

%% create Light Bartlein orange-white-purple diverging scheme
LB=flipud(lbmap(256,'BrownBlue')); % flip it so blue is for negative(ocean)
% and green for positive (land)

%% plot map
fig2 = figure;
imagesc(flipud(topo));
axis equal
axis tight
axis off
set(fig2,'Position',[720 400 980 580]);
title(' Non-symmetric divergent orange-white-purple palette','Color',...
'k','FontSize',12,'FontWeight','demi');
colormap(LB);
colorbar;

And here is the result below. I like this color scheme better than many othera for divergent data. One only issue in the figure, although not inherently due to the palette itself [2], is that the centre of the palette is not at the zero. This is a problem since the zero is such an important element in ratio data, in this case representing sea level.

MAKING THE PALETTE SYMMETRIC AROUND THE ZERO

The problem fortunately can be easily fixed by clipping the data limit to a symmetric range. In Matlab this has to be done programmatically, and rather than going about it with trial and error I like to do it automatically with the code below:

%% establish anchor to centre colormap midpoint at zero value
% calculate the difference between the signed most negative and most
% positive values in  data and use both the numerical result and its sign
% to assign the colormap automatically. This will anchor the midpoint
% to the zero in the data.
M=abs(max(max(topo)));
m=abs(min(min(topo)));
if M-m>=0
clim=[-m m];
else
clim=[-M M];
end

%% plot new map and compare
fig3 = figure;
imagesc(flipud(topo),[clim]);
axis equal
axis tight
axis off
set(fig3,'Position',[720 400 980 580]);
title('Symmetric divergent orange-white-purple palette','Color','k',...
'FontSize',12,'FontWeight','demi');
colormap(LB);
colorbar;

And here is the result; now it looks perfect.

COLOR VISION DEFICIENCY SIMULATIONS

To test the claim that this color palette is not confusing for viewers with color vision deficiency I run three simulation using the Vischeck plugin for ImageJ (see the related contents section for more details, and also check the Color Blind Essentials ebook) to show how viewers with Protanopia, Deuteranopia, and Tritanopia would see the map above. Here they are, and I think they passed the test. Let me know what you think.

FOOTNOTES

[1] I do indeed recommend it for geoscience ratio data;  I also do suggest it it for seismic data as a better alternative to the similar red-white-blue because the colors in the latter are more confusing. However,  neither is optimal because of the white at the low amplitude values. I’d recommend a neutral gray. But that’s another story, which I will tell at the end of my series on color palettes.

[2]  The issue arises from the fact that the data limits are not symmetric, with most negative extreme (lowest areas of the ocean floor) being higher in absolute value than the most positive extreme (highest areas on land). Notice that the demo data were clipped to begin with.

RELATED POSTS (MyCarta)

A rainbow for everyone

Better Palettes

Is Indigo really a colour of the rainbow?

The rainbow is dead…long live the rainbow! – Part 1

The rainbow is dead…long live the rainbow! – Part 2: a rainbow puzzle

Why is the hue circle circular at all?

RELATED CONTENT (External)

Color Blind Essentials eBook

Vischeck

Vischeck simulations using ImageJ plugin

Vischeck simulations online