Color bar for filled contour map display


H = contourcbar(...)


H = contourcbar(...) creates a color bar associated with a filled contour display created with contourfm, contourm, contour3m, or geoshow. It supports the same syntax and usage options as the MATLAB® function colorbar.


Add a colorbar to a map showing the topography of North America:

worldmap('north america')
load topo
R = georasterref('RasterSize',[180 360], ...
   'Latlim',[-90 90],'Lonlim',[0 360]);
contourfm(topo, R, -7000:1000:3000)
caxis([-8000 4000])

Add a colorbar to a map showing a geoid with non-uniform levels:

ax = worldmap('world');
load geoid
R = georasterref('RasterSize',[180 360], ...
   'Latlim',[-90 90],'Lonlim', [0 360]);
levels = [-70 -40 -20 -10 0 10 20 40 70];
geoshow(geoid, R, 'DisplayType', 'contour',...
coast = load('coast.mat');
geoshow(, coast.long, 'Color', 'white', 'LineWidth', 1.5)
cb = contourcbar('peer',ax,'Location','southoutside');
caxis([-110 90])
set(get(cb,'XLabel'),'String','Geoid Undulation in Meters')

More About

expand all


  • If a peer axes is specified when calling contourcbar, it should be a map axes containing an object created using one of the Mapping Toolbox™ functions listed previously. Otherwise the current axes should contain such an object.

  • If a Mapping Toolbox contour object is present, then the color bar is filled with solid blocks of color which bound each other at the contour levels used in the plot. Thus, the contour levels bounding a fill polygon of a given color can be inferred graphically by inspecting the upper and lower limits of the corresponding block in the color bar. In the absence of a Mapping Toolbox contour object an ordinary color bar is created.

  • If multiple Mapping Toolbox contour objects are present in the same axes, then the levels used to divide the color bar into blocks will correspond to the first contour object that is found. This situation could occur when a larger data set is broken up into multiple grid tiles, for example, but as long the tiles all use the same contour level list, the color bar will correctly represent them all.

Was this topic helpful?