Main Content

contourcmap

Contour colormap and color bar

Description

contourcmap(cmap) sets the colormap of the current figure (and current axes) to a predefined colormap. If the current axes contains a contour object created by the contourm, contourfm, contour3m, or geoshow function, then the number of colors in the colormap matches the number of contour intervals. Otherwise, the colormap contains 10 colors.

contourcmap(cmap,cdelta) updates the colormap of the current figure using the contour levels specified by cdelta. If the current axes contains a contour object created by the contourm, contourfm, contour3m, or geoshow function, then the contourcmap function ignores the value of cdelta.

example

contourcmap(___,Name,Value) specifies options for the color bar using name-value arguments, in addition to any combination of input arguments from the previous syntaxes. For example, display the color bar by specifying "Colorbar","on".

example

h = contourcmap(___) returns the color bar.

Examples

collapse all

Create a filled contour plot of world elevations. Specify three contour levels (which creates four contour intervals).

load topo60c
worldmap world
contourfm(topo60c,topo60cR,3)
plabel off
mlabel off

Figure contains an axes object. The hidden axes object contains 10 objects of type patch, line.

Change the colormap and add a labeled color bar. Note that the colormap uses the same number of contour intervals.

contourcmap("summer","Colorbar","on", ...
   "Location","horizontal","TitleString","Contour Levels in Meters")

Figure contains 2 axes objects. Axes object 1 with title Contour Levels in Meters contains an object of type image. Hidden axes object 2 contains 10 objects of type patch, line.

Create a world map containing elevation data and coastline data. Display the elevation data using a surface.

load topo60c
load coastlines
worldmap world
geoshow(topo60c,topo60cR,"DisplayType","surface")
geoshow(coastlat,coastlon,"Color","k")
mlabel off
plabel off

Figure contains an axes object. The hidden axes object contains 5 objects of type patch, surface, line.

Change the colormap, specifying a new contour level every 2000 meters, and add a labeled color bar.

contourcmap("summer",2000,"Colorbar","on", ...
   "Location","horizontal", ...
   "TitleString","Contour Levels in Meters")

Figure contains 2 axes objects. Axes object 1 with title Contour Levels in Meters contains an object of type image. Hidden axes object 2 contains 5 objects of type patch, surface, line.

Read and display spatially referenced geoid heights from the EGM96 geoid model. Change the colormap, specifying a new contour level every 10 meters, and add a labeled color bar.

[N,R] = egm96geoid;
worldmap(N,R)
geoshow(N,R,"DisplayType","surface")
plabel off
mlabel off

contourcmap("turbo",10,"Colorbar","on","Location","horizontal", ...
    "TitleString","Contour Levels in Meters")

Figure contains 2 axes objects. Axes object 1 with title Contour Levels in Meters contains an object of type image. Hidden axes object 2 contains 4 objects of type patch, surface, line.

Change the colormap again. To restrict the range of colors, specify the contour levels using a vector of evenly-spaced values. The map displays geoid heights outside the range using the color associated with the nearest contour level.

range = 0:5:50; 
contourcmap("turbo",range,"Colorbar","on","Location","horizontal", ...
    "TitleString","Contour Levels in Meters")

Figure contains 2 axes objects. Axes object 1 with title Contour Levels in Meters contains an object of type image. Hidden axes object 2 contains 4 objects of type patch, surface, line.

Input Arguments

collapse all

Colormap, specified as one of the options in the table. This argument accepts any predefined colormap accepted by the colormap function.

Colormap NameColor Scale
"parula"

Color bar showing the colors of the parula colormap. The colormap starts at dark blue and transitions to lighter blue, green, orange and yellow. The transitions between colors are more perceptually uniform than in most other colormaps.

"turbo"

Color bar showing the colors of the turbo colormap. The colormap starts at dark blue and transitions to lighter blue, bright green, orange, yellow, and dark red. This colormap is similar to jet, but the transitions between colors are more perceptually uniform than in jet.

"hsv"

Color bar showing the colors of the hsv colormap. The colormap starts at red and transitions to yellow, bright green, cyan, dark blue, magenta, and bright orange.

"hot"

Color bar showing the colors of the hot colormap. The colormap starts at dark red and transitions to bright red, orange, yellow, and white.

"cool"

Color bar showing the colors of the cool colormap. The colormap starts at cyan and transitions to light blue, light purple, and magenta.

"spring"

Color bar showing the colors of the spring colormap. The colormap starts at magenta and transitions to pink, light orange, and yellow.

"summer"

Color bar showing the colors of the summer colormap. The colormap starts at medium green and transitions to yellow.

"autumn"

Color bar showing the colors of the autumn colormap. The colormap starts at bright orange and transitions to yellow.

"winter"

Color bar showing the colors of the winter colormap. The colormap starts at dark blue and transitions to bright green.

"gray"

Color bar showing the gray colormap. The colormap starts at black and transitions to white.

"bone"

Color bar showing the bone colormap. This colormap has colors that are approximately gray with a slight blue color tint. The colormap starts at dark gray and transitions to white.

"copper"

Color bar showing the copper colormap. This colormap starts at black and transitions to a medium orange, similar to the color of copper.

"pink"

Color bar showing the pink colormap. This colormap starts at dark red and transitions to dark pink, tan, and white.

"jet"

Color bar showing the colors of the jet colormap. The colormap starts at dark blue and transitions to light blue, bright green, orange, yellow, and dark red.

"lines"

Color bar showing the colors of the lines colormap. The colormap contains a repeating pattern of colors: dark blue, dark orange, dark yellow, dark purple, medium green, light blue, and dark red.

"colorcube"

Color bar showing the colors of the colorcube colormap. The colormap is a course sampling of the RGB colorspace.

"prism"

Color bar showing the colors of the prism colormap. The colormap contains a repeating pattern of colors: red, orange, yellow, green, blue, and purple.

"flag"

Color bar showing the colors of the flag colormap. The colormap contains a repeating pattern of colors: red, white, blue, and black.

"white"

Color bar showing the white colormap, which is entirely white.

Data Types: char | string

Contour levels, specified as a numeric scalar or a numeric vector of evenly spaced values.

  • If cdelta is a scalar, then the function generates new contour levels at multiples of cdelta.

  • If cdelta is a vector of evenly spaced values, then the function generates new contour levels at those values.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: contourcmap("turbo",Colorbar="on") changes the colormap of the figure to "turbo" and displays a color bar

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: contourcmap("turbo","Colorbar","on") changes the colormap of the figure to "turbo" and displays a color bar

Note

In addition to the name-value arguments in this section, you can use name-value arguments to specify values for the properties of the Axes object returned by this function. For more information about the properties of Axes objects, see Axes Properties.

Visibility of the color bar, specified as one of these options:

  • "on" — Display a color bar.

  • "off" — Do not display a color bar.

Data Types: char | string

Location of the color bar with respect to the axes, specified as one of these options:

  • "vertical" — Display the color bar vertically and to the right of the axes.

  • "horizontal" — Display the color bar horizontally and below the axes.

  • "none" — Do not display a color bar.

Data Types: char | string

Alignment of the labels in the color bar, specified as one of these options:

  • "center" — Center the labels on the color bands.

  • "ends" — Center the labels on the color breaks.

If the figure contains contour objects created by the contourm, contourfm, contour3m, or geoshow function, the contourcmap function sets the value of this argument to "center" for contour lines and "ends" for filled contours, regardless of the option you specify.

Data Types: char | string

Graphics object that determines the colormap limits, specified as a graphics object.

Title of the color bar, specified as a character vector or string scalar.

Data Types: char | string

x-label of the color bar, specified as a character vector or string scalar.

Data Types: char | string

y-label of the color bar, specified as a character vector or string scalar.

Data Types: char | string

Output Arguments

collapse all

Output color bar, returned as an Axes object.

Version History

Introduced before R2006a