| MATLAB Function Reference | ![]() |
ColorSpec is not a function; it refers to the three ways in which you specify color for MATLAB® graphics:
RGB triple
Short name
Long name
The short names and long names are MATLAB strings that specify one of eight predefined colors. The RGB triple is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color; the intensities must be in the range [0 1]. The following table lists the predefined colors and their RGB equivalents.
RGB Value | Short Name | Long Name |
|---|---|---|
The eight predefined colors and any colors you specify as RGB values are not part of a figure's colormap, nor are they affected by changes to the figure's colormap. They are referred to as fixed colors, as opposed to colormap colors.
Some high-level functions (for example, scatter) accept a colorspec as an input argument and use it to set the CData of graphic objects they create. When using such functions, take care not to specify a colorspec in a property/value pair that sets CData; values for CData are always n-length vectors or n-by-3 matrices, where n is the length of XData and YData, never strings.
To change the background color of a figure to green, specify the color with a short name, a long name, or an RGB triple. These statements generate equivalent results:
whitebg('g')
whitebg('green')
whitebg([0 1 0]);You can use ColorSpec anywhere you need to define a color. For example, this statement changes the figure background color to pink:
set(gcf,'Color',[1,0.4,0.6])
bar, bar3, colordef, colormap, fill, fill3, whitebg
Color Operations for related functions
![]() | colormapeditor | colperm | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |