Cyclic colormap for visualizing angles

119 views (last 30 days)
Aamir
Aamir on 9 Nov 2011
Edited: DGM on 26 Nov 2023
I am visualizing angles of a norm-preserving vector field, please see http://www.flickr.com/photos/aamirahmed/6328889041/in/photostream The colors in this photo represent the direction of the vector (relative to +x axis) at that point.
With the built-in colormaps, there is an abrupt change in the colors between -180 and 180. This is very misleading, since angles are cyclic numbers, for example 90 and 100 are as close to each other as 175 and -175.
I think this problem can be addressed by using a cyclic colormap. By cyclic colormap, I mean when approaching the maximum value in the colormap, it blends into the minimum value, with no abrupt change in between.
Does anybody else here feel for the need of a cyclic colormap for this purpose? Please share if you already have a cyclic colormap. Also please suggest other solutions to address this problem.

Accepted Answer

Chad Greene
Chad Greene on 9 May 2016
I've written a phasemap function for this, built on Kristen Thyng's cmocean phase colormap. It has an approximately constant lightness profile, which places even emphasis on all phase values.

More Answers (3)

Dr. Seis
Dr. Seis on 9 Nov 2011
You can pick out your favorite colormap (doc colormap for examples) and then just wrap it around itself. So, for example, you can create:
jet_wrap = vertcat(jet,flipud(jet));
Then you just add this line after you plot:
colormap(jet_wrap);
Does this do what you want?... because it will make it so that abs(angle) equals the same color.
  1 Comment
Chad Greene
Chad Greene on 9 May 2016
Edited: Chad Greene on 12 May 2016
There is an issue with flipping and concatenating--often when phase is plotted we want to know whether phase is increasing or decreasing. If the colors go in one direction, then go in reverse order, there is no to ability to distinguish between increasing phase or decreasing phase.

Sign in to comment.


Walter Roberson
Walter Roberson on 9 Nov 2011
How about using the colormap named "hsv" ?
  2 Comments
Aamir
Aamir on 9 Nov 2011
I thought about HSV but it contains too many different and distracting colors. See here http://www.twitpic.com/7chnll
Walter Roberson
Walter Roberson on 9 Nov 2011
hmap(1:256,1) = linspace(0,1,256);
hmap(:,[2 3]) = 0.7; %brightness
huemap = hsv2rgb(hmap);
colormap(huemap)

Sign in to comment.


DGM
DGM on 26 Nov 2023
Edited: DGM on 26 Nov 2023
Here's a comparison, for what it's worth. I'm using multiple FEX tools here, so obviously this won't run if you don't go get the corresponding tools from the File Exchange.
% some colormaps
CT1 = phasemap(256); % Chad's phasemap()
CT2 = ccmap('hsyp',256); % MIMT ccmap()
CT3 = hsv(256); % base MATLAB
% can we subdue the hsv() map?
hmap(1:256,1) = linspace(0,1,256);
hmap(:,2) = 0.6; % saturation
hmap(:,3) = 0.7; % value
CT4 = hsv2rgb(hmap);
% visualize them
stripe = ctflop(cat(3,CT1,CT2,CT3,CT4));
image(stripe)
The 'hsyp' map from ccmap() isn't quite as uniform as phasemap(), but that comes with the low cost of using HSYp. It's a bit lighter than phasemap(), which may be good or bad, depending on what you want. I originally made it for line/mesh plots against a black background.
Using hsv() is one option, though it's not uniform. Much like with any rainbow map, one could argue that the regularity and distinctness of the primary-secondary intervals is a feature, but that's open for dispute. If the peakiness is undesired, desaturating hsv() doesn't do much to subdue the prominence of the secondary peaks.
Chad's phasemap() has some extra features, including the ability to provide a circular phase "color ring" for your figure.
There are other cyclic maps to be found. I think crameri() deserves mention, though you should probably do you own search and see what works best for you.
% cyclic maps from Chad Greene's crameri()
CT1 = crameri('romao');
CT2 = crameri('bamo');
CT3 = crameri('broco');
CT4 = crameri('corko');
CT5 = crameri('viko');
% visualize them
stripe = ctflop(cat(3,CT1,CT2,CT3,CT4,CT5));
image(stripe)
These are the FEX submissions I used.

Categories

Find more on Colormaps in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!