File Exchange

image thumbnail

cmocean perceptually-uniform colormaps

version 1.5 (691 KB) by Chad Greene
Perceptually-uniform colormaps inspired by oceanography

170 Downloads

Updated 28 Sep 2018

View License

These colormaps were developed by Kristen Thyng using viscm. They are perceptually uniform, as color should be when it serves as a numeric axis.

If these colormaps are useful for you, please consider citing our paper:

Thyng, K.M., C.A. Greene, R.D. Hetland, H.M. Zimmerle, and S.F. DiMarco. 2016. True colors of oceanography: Guidelines for effective and accurate colormap selection. Oceanography 29(3):9–13. http://dx.doi.org/10.5670/oceanog.2016.66

Comments and Ratings (21)

Jarrell Smith

Nice set of functions for extending the default set of colormaps.

bingkun luo

Chad Greene

Thanks Phelype! I've updated the function as per your suggestion.

I also stumbled upon the problem with the using the number of levels and the 'pivot' argument.
This is a bug in the argument parser. I propose the following fix:
Change the line (150) that says:
tmp = any([strncmpi(varargin,'pivot',3) strncmpi(varargin,'zero',3)]);
to
tmp = strncmpi(varargin,'pivot',3) | strncmpi(varargin,'zero',3);
It works for me after this change.

Fabian Grosse

Hi, first off - this is a really helpful and great looking set of colours!
I came across the same problem as Andrea these days, and worked on a solution which works satisfactorily for me. I am happy to share, just don't know how to do this best.

Andrea

Andrea (view profile)

Is it possible to specify the number of levels AND a pivot value?
For example: cmocean('balance',12,'pivot',0)
I seem to cannot make it work. It does the same as cmocean('balance','pivot',0) ignoring the number of levels

Andrea

Andrea (view profile)

Léa Olivier

E. Cheynet

Geroge James

Thank you Chad. That definitely helps. Maybe one of those could be an optional argument?
And thank you for directing me to the colorspace package.

Chad Greene

Hi David,

Thanks for the feedback. I see what you're saying about the off-white values in the center of the colormaps. These colormaps are the ones described in the paper published in Oceanography, and I think the rationale for not quite going all the way to pure white was to keep the colormap from blending in with a white background. I'm a bit colorblind myself, so I don't feel qualified to tinker with the colormaps. If you'd like to tinker on your own, get Pascal Getreuer's wonderful colorspace transformation function and try this:

C = cmocean('delta');

% Convert the colorspace:
hsl = colorspace('rgb->hsl',C);

% The lightness is the third column:
L = hsl(:,3);

% Make the peak white by setting its lightness to 100%
% Shift the lightness up a little to lighten the entire colormap:
L2 = L + (1-max(L));

% Or stretch the lightness values if you prefer to keep the low ends:
L2 = L/max(L);

% Convert back to RGB:
C2 = colorspace('hsl->rgb',[ hsl(:,1:2) L2]);

figure
plot(L,'b'); hold on;
plot(L2,'r')
ylabel 'lightness'
colorbar
colormap(C2)

Thank you for creating these colormaps! They have been extremely useful.

I do have some comments about the divergent colormaps. The center value doesn't come out white. For the delta colormap it returns an ugly yellow tinge to the background. The curl colormap leaves a slight red, and balance leaves an even slighter red. I have tried to use the zero/pivot command and it has not made a difference.
The issue appears to lie in the autopivot section (the code block after line 212). There is no specification that an RGB value of [1 1 1] should be returned in the middle of the colormap. Can this please be added into the code? It will be a fantastic improvement so that the background will actually be white.

Chad Greene

Hi Ola,

As a lowly graduate student I certainly appreciate the citations, thanks. The cmocean colormaps are available in GMT-friendly cpt format here: https://github.com/kthyng/cmocean-gmt

Ola Kalen

Sorry, my mistake, 0 -> blue just as you say.
OT: Will definitely cite Thyng et al in my next paper, hopefully out before summer. Any plans for a GIS package?

Chad Greene

Hi Ola,

Thanks for the kind words.

The "ice" colormap is designed to mimic the way sea ice looks in the ocean. Zero concentration of sea ice looks like a dark blackish blue, whereas 100% sea ice cover is nearly pure white.

If you prefer to flip the order of any colormap, the flipud command is one way to do it. A simpler way is to use the - sign when you call the colormap. For example,

cmocean -ice

Let me know if you think of other ways cmocean can be more user friendly or improved in any way.

Ola Kalen

Very good, thanks! To make it even better, maybe the "ice" colormap should be inverted in the package? It´s easy enough to use "flipud" to fix it, but maybe not for a beginner.

yi Wang

excellent
wish extend as python can be added

Thanks very much, seems the behavior of either imread or image changed; to get the correct image in release R2016b when doing cmocean with nargin==0, line 104 of cmocean should be

image(flipud(imread('cmocean.png')));

Updates

1.5

Modified input parser, following a suggestion by Phelype Oleinik. Also, now, if no outputs are specified it sets the colormap of the current axes via colormap(gca,cmap) whereas previously it was simply colormap(cmap).

1.4.0.0

Documentation fix.

1.4.0.0

Added a new "negative" option for divergent colormaps.

1.3.0.0

The 'zero' option for diverging colormaps has been extended to a 'pivot' syntax, which allows setting a pivot point to any value, zero or otherwise.

1.2.0.0

Added a link to our Oceanography paper. Also added the feature to simply type "cmocean" to bring up a window showing colormap options.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor

cmocean