Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

ColorSpec (Color Specification)

Color specification

Description

ColorSpec is not a function; it refers to the three ways in which you specify color for MATLAB® graphics:

  • RGB triplet

  • Short name

  • Long name

The short names and long names are character vectors that specify one of eight predefined colors. The RGB triplet 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 triplet equivalents.

RGB Triplet

Short Name

Long Name

[1 1 0]

y

yellow

[1 0 1]

m

magenta

[0 1 1]

c

cyan

[1 0 0]

r

red

[0 1 0]

g

green

[0 0 1]

b

blue

[1 1 1]

w

white

[0 0 0]

k

black

Examples

To change the background color of a figure to green, specify the color with a short name, a long name, or an RGB triplet. These statements generate equivalent results:

whitebg('g')
whitebg('green')
whitebg([0 1 0]);

This code changes the figure background color to pink:

fig = gcf;
fig.Color = [1 0.4 0.6];

More About

collapse all

Tips

The eight predefined colors and any colors you specify as RGB triplets 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.

In most cases, you can specify a color using either an RGB triplet or a character vector of a color name. However, in some cases, you cannot specify the color as a color name. For example, you cannot set the CData property of a scatter object to a color name.

Was this topic helpful?