You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
mcm - Make Color Map
Easily make colormaps with an input array of color values, designed to be simple to use and is ideal for beginners.
mcm() accepts numeric/rgb and hexidecimal as arrays where the rows correspond to individual colors in the map. mcm() also accepts MATLAB abbreviations as a single char or string, as in the example below.
All inputs must be of the same type (cannot use mix of numeric and hex, for example).
Length of the colormap and interpolation type may be specified, but these are optional inputs.
% Accepts any color input type.
% A red-white-blue colormap can be defined with
mapLength = 100; % Optional, Default = 256;
interType = 'nearest'; % Optional, Default = 'linear';
colors = 'rwb'; % These three inputs are all
colors = [1 0 0;1 1 1;0 0 1]; % accepted and produce identical
colors = ['#ff0101';'#ffffff';'#0101ff']; % colormaps in 'yourMap'.
yourMap = mcm(colors,mapLength,interpType);
colormap(gca,yourMap);
If a single color is input, yourMap will be a colormap that is centred about the input color that transitions from dark to light.
colors = 'm';
yourMap = mcm(colors);
If no input is given, mcm will generate a red-white-blue colormap that uses the MATLAB default red and blue from 'colororder'.
co = colororder;
colors = [co(1,:);% co(1,:) => MATLAB's default blue for plotting, first color used in plot(x,y)
[1 1 1]; % white, equivalent to 'w'.
co(5,:)];% co(5,:) => MATLAB's default red for plotting, fifth color used in plot(x,y)
yourMap1 = mcm(colors);
yourMap2 = mcm;
% isequal(yourMap1,yourMap2) = 1;
The latest version includes several predefined colormaps. They are detailed in the demo and in the comments of mcm(). Colormaps are
mapName = 'traffic';
mapName = 'cividis';
mapName = 'disco';
mapName = 'heatCam';
mapName = 'disco';
Colormap names are not case sensitive, and partial names (at least four characters) are sufficient to identify a particular colormap.
Cite As
John Kearns (2026). Easily make custom colormaps with any input type. (https://au.mathworks.com/matlabcentral/fileexchange/132767-easily-make-custom-colormaps-with-any-input-type), MATLAB Central File Exchange. Retrieved .
Acknowledgements
Inspired by: red-white-blue color map
General Information
- Version 1.1.0 (5.63 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
