This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


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.


collapse all

Create world map.

worldmap('north america')

Load topographical data from MAT-file topo.mat .

load topo

Create geographic raster reference object.

R = georasterref('RasterSize',[180 360], ...

Create a contour plot where every contour is filled with a particular color.

contourfm(topo, R, -7000:1000:3000)
caxis([-8000 4000])

Add a color bar to the figure to explain the color used with the contours.


Create a world map.

ax = worldmap('world');

Move the meridian labels to the bottom, and reduce the number of labels.


Load the geoid data set MAT-file.

load geoid60c

Specify levels (in meters) at which to contour the geoid.

levels = [-70 -40 -20 -10 0 10 20 40 70];

Display the geoid as a filled contour plot.

geoshow(geoid60c, geoid60cR, 'DisplayType', 'contour',...

Load the coastline data MAT file, coastlines.mat .

load coastlines

Overlay the coastlines.

geoshow(coastlat, coastlon, 'Color', 'white', 'LineWidth', 1.5)

Add a color bar to indicate the range in geoid height spanned by each contour interval.

cb = contourcbar('peer',ax,'Location','southoutside');

Reset the color map and the axes color limits (CLim).

caxis([-110 90])
cb.XLabel.String = 'Geoid Undulation in Meters';


  • 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.

Introduced in R2011b

Was this topic helpful?