Generates a RED-BLUE colormap with zero as white or black. Positive values are displayed as blue intensities and negative values are displayed as red intensities. Zero can be selected to be either white or black. The clim values, from the image or can be entered, are used to customize the colormap.
Syntax: y = redblue(n,clim,'black')
Typical usage: colormap(redblue(64))
Arguments:
All arguments are optional and can be in any order.
n - number of color levels (default is # of colors of current colormap)
clim - two element vector specifying the color limits (default: current axis color limits)
black - string ('k' or 'black') specifying zero as black (default is zero as white)
This creates a custom colormap for any image. The colorbar scale will be skewed toward red or blue depending on the caxis values (clim) of the image.
Two versions:
redblue.m - This version flattens the edges of the colormap to improve the visualization of the
gradient. The effect works better for larger values of n.
redblueu.m - This version uses a uniform scaling for red and blue. The white and black will appear
to be a larger section.
Keep in mind that if the scale is very skewed, there will not be much of a color gradient. The gradient can always be increased by using your own clim values.
% Example:
% y = caxis; % e.g. y = [-11,-5]
% colormap(redblue(64) % and not much gradient
% colormap(redblue(64,[-11,0])) % white is at -5 with a larger gradient
引用格式
Mirko Hrovat (2024). RedBlue Colormap Generator with Zero as White or Black (https://www.mathworks.com/matlabcentral/fileexchange/74791-redblue-colormap-generator-with-zero-as-white-or-black), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!