textcolorbar documentation

The textcolorbar function creates a color-scaled text that is something between a colorbar and a text legend. It does not hijack the current colormap.

Back to Climate Data Tools Contents.



h = textcolorbar


textcolorbar(labels) places a color-scaled text label legend in the upper left hand corner of the current axes. If labels is a numeric array, then the color of each label is scaled according to the range of values in labels. If labels is a cell array of strings, each cell becomes a row in the color-scaled legend.

textcolorbar(...,'colormap',col,...) specifies an Mx3 colormap. If input labels are numeric, the colors of each row in the text legend are interpolated from the specified colormap. If input labels are cell strings, the colormap must have the same number of rows as the number of cells in labels. The default colormap is parula.

textcolorbar(...,'location',loc,...) specifies a location as:

textcolorbar(...,'TextProperty',TextValue,...) sets any text properties as name-value pairs.

h = textcolorbar(...) returns a handle h of the color-scaled text object.


Start with this example plot:

% Load some example data:
[X,Y,Z] = peaks(500);

shading interp
caxis([-1 15])
cmocean amp

Place two text colorbars in the top corners of the figure:

% 1 to 5 in the upper left-hand corner:

% Discontinuous number range in the upper right:
textcolorbar([1:4 50],'loc','ne')

In the figure above, both text colorbars contain five numbers, but the color mapping is different. That's because the numbers in the first colorbar are equally spaced, whereas the numbers in the second colorbar span a large range of numbers that are not printed in the colorbar.

In this example, use the thermal colormap (instead of the default parula) and format the text as large, bold numbers. Place it in the

   'loc','eo') % location is eo, or "east outside"

Now print five text labels, equally spaced along the default parula colormap:

lifestages = {'newborn','infant','toddler','teen','adult'};


Map five text labels to the 'algae' colormap by specifying a 5x3 matrix of the RGB values:


Here's another set of text labels and their corresponding values:

strings = {'red','orange','yellow','green','blue','indigo','violet'};

col = rgb(strings);


Author Info

This function is part of the Climate Data Toolbox for Matlab. The function and supporting documentation were written by Chad A. Greene of NASA Jet Propulsion Laboratory.