Code covered by the BSD License  

Highlights from
Vivid Colormap

5.0

5.0 | 9 ratings Rate this file 50 Downloads (last 30 days) File Size: 2.74 KB File ID: #20848
image thumbnail

Vivid Colormap

by

 

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.

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 (14)
29 Sep 2012 Hassan

just perfect!

12 Sep 2012 Sven

Well done. Very useful and well designed/documented.

12 Sep 2012 Sven  
26 Apr 2012 chrysa  
12 Dec 2011 James  
12 Dec 2011 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.

09 Dec 2011 Jiro Doke

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!

09 Dec 2011 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.

08 Dec 2011 Jiro Doke

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.

Updates
09 Dec 2011

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