Main Content

Colormaps for Political Maps

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.


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.

Explore Colormaps for Political Maps

Display the usastatelo data set as patches, setting up the map with worldmap and plotting it with geoshow. Note that the default face color is yellow.

worldmap na
states = shaperead('usastatelo', 'UseGeoCoords', true);

Use polcmap to populate color definitions to a symbolspec to recolor the patches randomly.

faceColors = makesymbolspec('Polygon',...
    {'INDEX', [1 numel(states)], 'FaceColor',...

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, seed the MATLAB® random number function using the rng function and a fixed value of your choice.

worldmap na
faceColors = makesymbolspec('Polygon',...
   {'INDEX', [1 numel(states)], 'FaceColor', polcmap(256,.2)});
geoshow(states, 'SymbolSpec', faceColors)

Labeling Colorbars

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'};

Editing Colorbars

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, Colormap Editor, described in the MATLAB Function Reference pages. Also see the MATLAB colormap function documentation.