3-D Visualization |

Each MATLAB figure window has a colormap associated with it. A colormap is simply a three-column matrix whose length is equal to the number of colors it defines. Each row of the matrix defines a particular color by specifying three values in the range 0 to 1. These values define the RGB components (i.e., the intensities of the red, green, and blue video components).

The `colormap`

function, with no arguments, returns the current figure's colormap.

For example, the MATLAB default colormap contains 64 colors and the 57th color is red.

This table lists some representative RGB color definitions.

Red |
Green |
Blue |
Color |

`0` |
`0` |
`0` |
Black |

`1` |
`1` |
`1` |
White |

`1` |
`0` |
`0` |
Red |

`0` |
`1` |
`0` |
Green |

`0` |
`0` |
`1` |
Blue |

`1` |
`1` |
`0` |
Yellow |

`1` |
`0` |
`1` |
Magenta |

`0` |
`1` |
`1` |
Cyan |

`0.5` |
`0.5` |
`0.5` |
Gray |

`0.5` |
`0` |
`0` |
Dark red |

`1` |
`0.62` |
`0.40` |
Copper |

`0.49` |
`1` |
`0.83` |
Aquamarine |

You can create colormaps with MATLAB array operations or you can use any of several functions that generate useful maps, including `hsv`

, `hot`

, `cool`

, `summer`

, and `gray`

. Each function has an optional parameter that specifies the number of rows in the resulting map.

creates an m-by-3 matrix whose rows specify the RGB intensities of a map that varies from black, through shades of red, orange, and yellow, to white.

If you do not specify the colormap length, MATLAB creates a colormap the same length as the current colormap. The default colormap is `jet(64)`

.

If you use long colormaps (> 64 colors) in each of several figure windows, it might become necessary for the operating system to swap in different color lookup tables as the active focus is moved among the windows.

**Displaying Colormaps**

The `colorbar`

function displays the current colormap, either vertically or horizontally, in the figure window along with your graph. For example, the statements

produce a surface plot and a vertical strip of color corresponding to the colormap. Note how the colorbar indicates the mapping of data value to color with the axis labels.

Coloring Mesh and Surface Plots | Indexed Color Surfaces -- Direct and Scaled Colormapping |

© 1994-2005 The MathWorks, Inc.