| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Mapping Toolbox |
| Contents | Index |
| Learn more about Mapping Toolbox |
| On this page… |
|---|
Colors and colorscales (ordered progressions of colors) are invaluable for representing geographic variables on maps, particularly when you create terrain and thematic maps. The following sections describe techniques and provide examples for applying colormaps and colorbars to maps.
In previous examples, the function demcmap was used to color several digital elevation model (DEM) topographic displays. This function creates colormaps appropriate to rendering DEMs, although it is certainly not limited to DEMs.
These colormaps, by default, have atlas-like colors varying with elevation or depth that properly preserve the land-sea interface. In cartography, such color schemes are called hypsometric tints.
Here you explore demcmap using the topographic data for the Korean peninsula provided in the korea data set. To set up an appropriate map projection, pass the korea data grid and referencing vector to worldmap:
load korea figure worldmap(map,refvec)
Display the data grid with geoshow:
geoshow(map, refvec, 'DisplayType', 'mesh')

The Korea DEM is displayed using the default colormap, which is inappropriate and causes the surface to be unrecognizable. Now apply the default DEM colormap:
demcmap(map)

You can also make demcmap assign all altitudes within a particular range to the same color. This results in a quasi-contour map with breaks at a constant interval. Now color this map using the same color scheme coarsened to display 500 meter bands:
demcmap('inc',map,500)
colorbarNote that the first argument to demcmap, 'inc', indicates that the third argument should be interpreted as a value range. If you prefer, you can specify the desired number of colors with the third argument by setting the first argument to 'size'.

You can create colormaps that make surfaces look like contour maps for other types of data besides terrain. The contourcmap function creates a colormap that has color changes at a fixed value increment. Its required arguments are the increment value and the name of a colormap function. Optionally, you can also use contourcmap to add and label a colorbar similarly to the MATLAB colorbar function:
Explore contourcmap by loading the world geoid data set and rendering it with a default colormap:
load geoid figure; worldmap(geoid,geoidrefvec) geoshow(geoid, geoidrefvec, 'DisplayType', 'surface')
Use contourcmap to specify a contour interval of 10 (meters), and to place a colorbar beneath the map:
contourcmap(10,'jet','colorbar','on','location','horizontal')

If you want to render a restricted value range, you can enter a vector of evenly spaced values for the first argument. Here you specify a 5-meter interval and truncate symbology at 0 meters on the low end and 50 meters at the high end:
contourcmap([0:5:50],... 'jet','colorbar','on','location','horizontal')

Should you need to write a custom colormap function, for example, one that has irregular contour intervals, you can easily do so, but it should have the N-by-3 structure of MATLAB colormaps.
Political maps typically use muted, contrasting colors that make it easy to distinguish one country from its neighbors. You can create colormaps of this kind using the polcmap function. The polcmap function creates a colormap with randomly selected colors of all hues. Since the colors are random, if you don't like the result, execute polcmap again to generate a different colormap:
To explore political colormaps, display the usastatelo data set as patches, setting up the map with worldmap and plotting it with geoshow:
figure
worldmap na
states = shaperead('usastatelo', 'UseGeoCoords', true);
geoshow(states)Note that the default face color is black, which is not very interesting.

Use polcmap to populate color definitions to a symbolspec to randomly recolor the patches and expand the map to fill the frame:
faceColors = makesymbolspec('Polygon',...
{'INDEX', [1 numel(states)], 'FaceColor',...
polcmap(numel(states))});
geoshow(states,'SymbolSpec',faceColors)

The polcmap function can also control the number and saturation of colors. Reissue the command specifying 256 colors and a maximum saturation of 0.2. To ensure that the colormap is always the same, reset the seed on the MATLAB random number function using the 'state' argument with a fixed value of your choice:
figure
worldmap na
rand('state',0)
faceColors = makesymbolspec('Polygon',...
{'INDEX', [1 numel(states)], 'FaceColor', polcmap(256,.2)});
geoshow(states, 'SymbolSpec', faceColors)

For maximum control over the colors, specify the ranges of hues, saturations, and values. Use the same set of random color indices as before.
figure
worldmap na
rand('state',0)
faceColors = makesymbolspec('Polygon', ...
{'INDEX', [1 numel(states)], ...
'FaceColor', polcmap(256,[.2 .5],[.3 .3],[1 1]) });
geoshow(states, 'SymbolSpec', faceColors)

Note The famous Four Color theorem states that any political map can be colored to completely differentiate neighboring patches using only four colors. Experiment to find how many colors it takes to color neighbors differently with polcmap. |
Political maps are an example of nominal data display. Many nominal data sets have names associated with a set of integer values, or consist of codes that identify values that are ordinal in nature (such as low, medium, and high). The function lcolorbar creates a colorbar having a text label aligned with each color. Nominal colorbars are customarily used only with small colormaps (where 10 categories or fewer are being displayed). lcolorbar has options for orienting the colorbar and aligning text in addition to the graphic properties it shares with axes objects.
figure; colormap(jet(5))
labels = {'apples','oranges','grapes','peaches','melons'};
lcolorbar(labels,'fontweight','bold');

Maps of nominal data often require colormaps with special colors for each index value. To avoid building such colormaps by hand, use the MATLAB GUI for colormaps, colormapeditor, described in the MATLAB Function Reference pages. Also see the MATLAB colormap function documentation.
![]() | Using Cartesian MATLAB Display Functions | Printing Maps to Scale | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |