Mapping Toolbox | ![]() ![]() |
Colormap for Terrain Data
In this tutorial, you may have noticed the use of the function demcmap
in several digital elevation map (DEM), or topographic, display examples. This function creates colormaps appropriate for the display of DEMs, although it is certainly not limited to just DEMs.
The colormaps, by default, have atlas-like colors varying with elevation or depth that properly preserve the land-sea interface.
You can also require that all altitudes within a particular range be assigned the same color. This effectively results in a contour map with color breaks at multiples of some level. Here is the same map with colors constant within 500 meter bands.
Contour Colormaps
You can create colormaps that make surfaces look like contour maps for other types of data besides terrain. The contourcmap
command creates a colormap that has color changes at multiples of a contour level increment. You need to specify the color increment and the name of a colormap function. You can write your own colormap function, but it should work like those provided with MATLAB. Optionally, you can also have contourcmap
add and label a colorbar that is similar to MATLAB's colorbar
.
load geoid worldmap(geoid,geoidlegend) contourcmap(10,'jet','colorbar','on','location','horizontal')
Colormap for Political Data
Political units are typically shown colored with muted, contrasting colors that make it easy to distinguish one country from another. A colormap of this kind can be created using the polcmap
command. The polcmap
command creates a colormap with randomly selected colors of all hues. Since the colors are random, if you don't like the result the first time, execute polcmap
again to generate a different colormap. To ensure that the colormap is always the same, reset the seed on MATLAB's random number generator rand
.
You can also control the saturation of the colors. Here is the same map with 256 colors and a maximum saturation of 0.1.
For maximum control over the colors, specify the limits on hues, saturations, and values.
Labeled Colorbars
Indexed maps often have names associated with the numeric index values. The lcolorbar
command allows you to create a colorbar with text labels aligned with the colors or color breaks.
figure; colormap(jet(5)) labels = {'apples','oranges','grapes','peachs','melons'}; lcolorbar(labels,'fontweight','bold');
Create Colormaps Interactively
Indexed maps often require colormaps with special colors for each index value. To avoid building such colormaps by hand, use the Graphical User Interface for colormaps, cmapui
. The cmapui
panel allows you to select color entries in a colormap by clicking on the colorbar. To change the color's hue and saturation, drag the color Marker on the color wheel. To control the value of the color in HSV space, drag the red Slider. Clicking the Accept button returns the modified colormap.
Here is the colormap panel with colors more appropriate to the labeled colorbar in the previous example.
![]() | Cartesian MATLAB Display Functions | Lights | ![]() |