Main Content

polcmap

Create colormap appropriate to political regions

Description

polcmap applies a random, muted colormap to the current figure. The size of the colormap is the same as the existing colormap. This function is useful for creating colormaps that help you distinguish one political region from its neighbors.

example

polcmap(ncolors) creates a colormap with the specified number of colors.

example

polcmap(ncolors,maxsat) controls the maximum saturation of the colors.

polcmap(ncolors,huelimits,saturationlimits,valuelimits) controls the hue, saturation, and value of the colors. polcmap randomly selects values within the limit vectors. These are two-element vectors of the form [min max]. Valid values range from 0 to 1. As the hue varies from 0 to 1, the resulting color varies from red, through yellow, green, cyan, blue, and magenta, back to red. When the saturation is 0, the colors are unsaturated; they are simply shades of gray. When the saturation is 1, the colors are fully saturated; they contain no white component. As the value varies from 0 to 1, the brightness increases.

cmap = polcmap(___) returns the colormap without applying it to the figure.

Examples

collapse all

Create an empty map axes with a Lambert conformal conic projection and map limits covering Texas.

figure
usamap("texas")

Read state boundaries from a shapefile into a geospatial table. Display the boundaries on the map, noting that the default face color is yellow.

states = readgeotable("usastatelo.shp");
geoshow(states,"DisplayType","polygon")

Define the colors you want to apply to the shapes (states) in a symbol specification. Use polcmap to create a colormap the same size as the number of rows in the geospatial table. polcmap creates a palette of muted colors.

h = height(states);
faceColors = makesymbolspec("Polygon", ...
     {'INDEX',[1 h],'FaceColor',polcmap(h)});

Display the map again using the symbol specification to color the patches (states) in the map. The colors you obtain for this example can vary each time you run this example because polcmap computes them randomly.

geoshow(states,"DisplayType","polygon","SymbolSpec",faceColors)

Read state boundaries from a shapefile into a geospatial table. Set to a variable the number of rows in the table.

states = readgeotable("usastatelo.shp");
h = height(states);

Create a colormap with 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.

rng(0)
cmap = polcmap(256,0.2);

Use the colormap to display the state boundaries on a map of North America.

figure
worldmap na
faceColors = makesymbolspec("Polygon",{'INDEX',[1 h],'FaceColor',cmap});
geoshow(states,"SymbolSpec",faceColors)

Input Arguments

collapse all

Number of colors in the color map, specified as a numeric scalar.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Maximum saturation of colors, specified as a numeric scalar. Larger maximum saturation values produce brighter, more saturated colors.

Data Types: single | double | logical | char

Color range limits, specified as a two-element vector of the form [min max]. Values range from 0 to 1.0. As the hue varies from 0 to 1, the resulting color varies from red, through yellow, green, cyan, blue, and magenta, back to red.

Data Types: single | double

Color saturation limits, specified as a two-element vector of the form [min max]. Values range from 0 to 1.0. When the saturation is 0, the colors are unsaturated; they are simply shades of gray. When the saturation is 1, the colors are fully saturated; they contain no white component.

Data Types: single | double

Brightness of colors, specified as a two-element vector of the form [min max]. Values range from 0 to 1.0. As the value varies from 0 to 1, the brightness increases.

Data Types: single | double

Output Arguments

collapse all

Colormap, returned as an m-by-3 numeric array of class double or class single, depending on the type of the input.

Tips

  • You cannot use polcmap to alter the colors of displayed patches drawn by geoshow or mapshow. The patches must have been rendered by displaym. However, you can color patches using polcmap when you call geoshow or mapshow (see Color Patches Using Random, Muted Colormap).

Version History

Introduced before R2006a