File Exchange

image thumbnail

Vivid Colormap

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


Updated 09 Dec 2011

View Version History

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

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
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

CMAP - an Mx3 colormap matrix

% Default Colormap
colormap(vivid); colorbar

% Mapping With 256 Colors
colormap(vivid(256)); colorbar

% Mapping With Full Intensity Range
colormap(vivid([0 1])); colorbar

% Mapping With Light Colors
colormap(vivid([.5 1])); colorbar

% Mapping With Dark Colors
colormap(vivid([0 .5])); colorbar

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

% Mapping With Color String
colormap(vivid('pmvbscaglyor')); colorbar

% Colormap With Multiple Custom Settings
colormap(vivid(64,[.1 .9],'bwr')); colorbar

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

Cite As

Joseph Kirk (2021). 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)


just perfect!


Well done. Very useful and well designed/documented.




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.


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;

But this would flip it.

By the way, I have highlighted this entry on this week's Pick of the Week:

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.


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:

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.


Tsann-Bim Chiou

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.

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.

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

Community Treasure Hunt

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

Start Hunting!