File Exchange

image thumbnail

Custom Colormap

version 1.1 (84 KB) by Víctor Martínez-Cagigal
This function is able to define a customized colormap given the positions and the colors that are required to make the gradients.

157 Downloads

Updated 11 Sep 2019

View Version History

View License

The function defines a customized colobar given the positions and the colors that are going to generate the gradients. A Live Script example is also provided to understand the following parameters:

- positions: Vector of positions, from 0 to 1. Note that the first position must be 0, and the last one must be 1.

- colors: Colors to place in each position. This parameter can be specified as a RGB matrix (n_colors x 3), or as a cell vector, containing HTML values. For instance: {'#ffffff','#ff0000','#000000'} is equivalent to [1 1 1; 1 0 0; 0 0 0].

*Update*: The function customcolormap_preset provides 8 new cool presets in order to save time configuring your own!. The presets are 'pasteljet', 'red-yellow-blue', 'red-yellow-green', 'red-white-blue', 'orange-white-purple', 'purple-white-green', 'pink-white-green', 'brown-white-pool'.

Example of use:
J = customcolormap([0 0.5 1], {'#ffffff','#ff0000','#000000'});
colorbar; colormap(J); axis off;

Cite As

Víctor Martínez-Cagigal (2021). Custom Colormap (https://www.mathworks.com/matlabcentral/fileexchange/69470-custom-colormap), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (17)

Andy Frassetto

fpeterf

MacMilan ZHANG

Tomer Nahshon

Matthew Heberger

Really nice function to help create attractive maps and plots. Thank you!

MADHUR PARASHAR

Yichuan Tang

very nice implementation !

Zili Yan

Chien-Han Su

Thomas Marangoni

sohrab

Erick Burgos Parra

Hi,
I keep getting this message when trying to use customcolormap_preset :
"error: 'm' undefined near line 112 column 28
error: called from
customcolormap at line 112 column 19"

I tried this small script;
prueba=rand(100,100);
imagesc(prueba)
a=customcolormap_preset('orange-white-purple')
colormap(a)

Any comments? Thank you

Javier

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