File Exchange

image thumbnail

Custom colormap

version (2.84 KB) by Erik Kvaleberg
Create custom colormaps from single or multiple RGB values.


Updated 01 Jul 2013

View License

CMAP creates a custom colormap based on RGB values in the MATLAB format(values between 0-1). By specifying a base color, for example green: [0 1 0], CMAP creates a colormap with a specified number of colors around this value, and omits the darkest/lightest colors based on user input. Combine several CMAP calls to create multi-color maps as the example image shows.

- Base color
- Number of colors in the colormap (optional)
- Percentage cut of darkest colors (optional)
- Percentage cut of lightest colors (optional)

By downloading RGB triple of color name, version 2 (File ID: #24497), by Kristjan Jonasson, CMAP input may be specified as color names ('seagreen', 'darkred', etc.)

figure; pcolor([0:20;0:20]); cmap([0 1 0],10,20,5); colorbar
This gives a colormap in green tones, with 10 colors. 20% of the darkest colors and 5% of the lightest colors have been cut.

The attached sample figure (global mean sea surface temperature in July) was plotted using:

Cite As

Erik Kvaleberg (2021). Custom colormap (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Kristin Fitzmorris

This is awesome! I have a question though: Is there an upper limit to how many different colors you can specify? I seem to be hitting a ceiling of 12001.

Erik Kvaleberg

Josh: Yes, if you set the "percentage cut of lightest colors" to zero, for example like this:

colormap(flipud(cmap([0 0 1],10,5,0)))

This will plot random values 0-1 with a colorbar from white to dark blue. Change the 10 and 5 numbers to set the number of discrete colors and the shade of blue (or any other color you choose).


I was wondering if it were possible to have the color scale begin to fade out from zero (i.e. the white would == 0 and then fade into color)?


MATLAB Release Compatibility
Created with R2012a
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!