Code covered by the BSD License  

Highlights from
Vivid Colormap

5.0
5.0 | 10 ratings Rate this file 23 Downloads (last 30 days) File Size: 2.74 KB File ID: #20848 Version: 1.3
image thumbnail

Vivid Colormap

by

Joseph Kirk (view profile)

 

24 Jul 2008 (Updated )

creates a personalized, vivid colormap

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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

Acknowledgements

This file inspired Advanced Colormap, Color Brewer: Attractive And Distinctive Colormaps, and Cubehelix Colormaps: Beautiful, Distinct, Versatile!.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
01 May 2015 Dennis A. Dean, II, Ph.D.

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)

29 Sep 2012 Hassan

Hassan (view profile)

just perfect!

12 Sep 2012 Sven

Sven (view profile)

Well done. Very useful and well designed/documented.

Comment only
12 Sep 2012 Sven

Sven (view profile)

 
26 Apr 2012 chrysa

chrysa (view profile)

 
12 Dec 2011 James

James (view profile)

 
12 Dec 2011 Joseph Kirk

Joseph Kirk (view profile)

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

Comment only
09 Dec 2011 Jiro Doke

Jiro Doke (view profile)

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!

Comment only
09 Dec 2011 Joseph Kirk

Joseph Kirk (view profile)

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

Comment only
08 Dec 2011 Jiro Doke

Jiro Doke (view profile)

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.

05 Oct 2011 Michael  
16 Mar 2010 Tsann-Bim Chiou

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

27 Jul 2008 jichao zhao

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

25 Jul 2008 Andrew Stevens

Whoops- forgot to rate in my previous review.

25 Jul 2008 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.

Comment only
Updates
09 Dec 2011 1.3

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.

Contact us