File Exchange

image thumbnail

Vivid Colormap

version 1.3.0.0 (2.74 KB) by Joseph Kirk
creates a personalized, vivid colormap

5 Downloads

Updated 09 Dec 2011

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

VIVID Creates a Personalized Colormap
VIVID(...) Creates a colormap with custom settings

Inputs:
M - (optional) an integer between 1 and 256 specifying the number of colors in the colormap. Default is 128.
MINMAX - (optional) is a 1x2 vector with values between 0 and 1 representing the intensity range for the colors, which correspond to black and white, respectively. Default is [0.15 0.85].
CLRS - (optional) either a Nx3 matrix of values between 0 and 1 representing the desired colors in the colormap
-or-
a string of characters that includes any combination of the following letters:
'r' = red, 'g' = green, 'b' = blue
'y' = yellow, 'c' = cyan, 'm' = magenta
'o' = orange, 'l' = lime green, 'a' = aquamarine
's' = sky blue, 'v' = violet, 'p' = pink
'k' or 'w' = black/white/grayscale

Outputs:
CMAP - an Mx3 colormap matrix

Example:
% Default Colormap
imagesc(sort(rand(200),'descend'));
colormap(vivid); colorbar

Example:
% Mapping With 256 Colors
imagesc(peaks(500))
colormap(vivid(256)); colorbar

Example:
% Mapping With Full Intensity Range
imagesc(peaks(500))
colormap(vivid([0 1])); colorbar

Example:
% Mapping With Light Colors
imagesc(peaks(500))
colormap(vivid([.5 1])); colorbar

Example:
% Mapping With Dark Colors
imagesc(peaks(500))
colormap(vivid([0 .5])); colorbar

Example:
% Mapping With Custom Color Matrix
imagesc(peaks(500))
clrs = [.5 0 1; 0 .5 1; 0 1 .5; .5 1 0; 1 .5 0; 1 0 .5];
colormap(vivid(clrs)); colorbar

Example:
% Mapping With Color String
imagesc(peaks(500))
colormap(vivid('pmvbscaglyor')); colorbar

Example:
% Colormap With Multiple Custom Settings
imagesc(sort(rand(300,100),'descend'));
colormap(vivid(64,[.1 .9],'bwr')); colorbar

Example:
% Topo Colormap
load topo;
imagesc(topo); axis xy; caxis([-6000 6000])
colormap(vivid('bg')); colorbar

Cite As

Joseph Kirk (2020). Vivid Colormap (https://www.mathworks.com/matlabcentral/fileexchange/20848-vivid-colormap), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (15)

I feel great at being out programmed on this one. I can now spend more time understanding my results. Great job. (I do intend to read the code at some point)

Hassan

just perfect!

Sven

Well done. Very useful and well designed/documented.

Sven

chrysa

James

Joseph Kirk

@Jiro, as per your suggestion, I made a modification to the file. Now the inputs are interpretted in order from low-to-high in accordance with the standard colormap convention.

jiro

Hi Joseph, I understand your logic. I guess it's just a difference in what we consider more intuitive. I think in terms of ascending order, so lowest (in value) to highest. Also I wanted it to keep the same logic for the usual colormaps in MATLAB. If I already had a colormap, and I wanted to "vivid-ify" it, I may want to do:

cm = colormap;
colormap(vivid(cm));

But this would flip it.

By the way, I have highlighted this entry on this week's Pick of the Week:
http://blogs.mathworks.com/pick/2011/12/09/a-vivid-colormap/

Thanks for the entry!

Joseph Kirk

@Jiro, thank you. In regards to your example, it is not a bug if it was intentional. :o) I thought it was more intuitive to input colors top-to-bottom so that if inputs are provided in a "rainbow order", users would not have to think about the color sequence in reverse. For example:
>> colormap(vivid('royg'));
would have red on top and green on the bottom, which I thought made more sense than:
>> colormap(vivid('gyor'))

However, if you do not like this feature, you can replace line 136 with the following:
>> rgb = repmat(reshape(clrs,1,nc,3),ns,1);
...where I just removed the call to flipud.

jiro

This is great Joseph! It's a very ingenious idea. I noticed a small bug. When you pass in a colormap (CLRS), it swaps the order. You can see the issue from this example:

imagesc(peaks(500))
colormap(jet(16)); colorbar
colormap(vivid(jet(16))); colorbar

Notice the "jet" colormap is swapped when I call with vivid - it goes from red to blue instead of blue to red.

Michael

This is one of the nice colormaps I've seen so far. Thanks.

jichao zhao

it is great work!!! And thanks for sharing with us.
jichao

Andrew Stevens

Whoops- forgot to rate in my previous review.

Andrew Stevens

Nicely done. Works well and I already received compliments from a colleague on the colormap generated with this code that I used for a figure.

Updates

1.3.0.0

As per Jiro's suggestion, I reversed the order of the input colors to mimic the low-to-high that is typical for most colormaps.

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