Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

 

COLORSCALE Add a color scale bar using part of the figure's colormap.
COLORSCALE creates a color scale for use with an integer-valued image
which has been encoded and quantized via a monotonic transformation
from a real-valued array. The original array has physically meaningful
units, but the image does not. The transformed image has been displayed
with a direct mapping to the figure's colormap. (That is, the IMAGE object
has a CDATAMAPPING of 'direct'.) The image and/or color scale may not
use the entire colormap. The colormap may contain special values for
null data areas, and these special values may be excluded from the
scale bar. Or, the colormap may be deliberately partitioned and shared
with a different image in the same figure, and that image may have its
own entirely distinct color scale. In these cases, unlike the COLORBAR
function in MATLAB, COLORSCALE can limit the displayed colors to the
appropriate interval within the figure's colormap. H = COLORSCALE(CMAPLIM,DATALIM,DATAINC,ORIENTATION,'Position',RECT)
adds a color scale to the current figure. The color scale uses the part
of the figure's colormap specified by limits in the 1-by-2 vector
CMAPLIM. The ticks on the vertical axis are in physical data units which
may be scaled and shifted with respect to the colormap indices and are
controlled by DATALIM and DATAINC. DATALIM is a 1-by-2 vector such that
DATALIM(1) and DATALIM(2) indicate the physical values corresponding to
the colors in rows CMAPLIM(1) and CMAPLIM(2), respectively, of the
colormap. DATALIM and DATAINC are in physical data units. DATALIM(2)
must exceed DATALIM(1), but CMAPLIM(2) may be less than CMAPLIM(1).
ORIENTATION should be either 'horiz' for horizontal or 'vert' for vertical.
RECT = [left, bottom, width, height] specifies the location and size of
the axis box containing the color scale (i.e., the 'Position' property
of the axes containing the color scale). Unlike COLORBAR, COLORSCALE
does not automatically decide where to place the axes. COLORSCALE
optionally returns the axes handle. H = COLORSCALE(...,PROP1,VAL1,PROP2,VAL2,...) sets additional
properties of the axes containing the color scale. Example
-------
% Create a figure with a jet colormap
figure
colormap jet % Create a standard colorbar
set(axes,'Visible','off')
bar = colorbar;
set(get(bar,'Title'),'String','Standard Colorbar')
pos = get(bar,'Position'); % Create a terrain height scale using part of the colormap
colorscale([31 54], [0 9000], 1000, 'vert',...
'Position',pos - [0.7 0 0 0])
title('Terrain Height')
ylabel('elevation above sea level, meters') % Create a bathymetry scale that uses a different part of the
% colormap and runs in reverse (i.e., CMAPLIM(1) > CMAPLIM(2)).
colorscale([24 1], [0 12000], 1000, 'vert',...
'Position',pos - [0.35 0 0 0],'YDir','reverse')
title('Bathymetry')
ylabel('depth below sea level, meters') See also COLORBAR, COLORMAP, COLORMAPEDITOR, AXES.
Contact sales
Subscribe to newsletters