Main Content

setColor

(Not recommended) Set color used to draw ROI object

setColor is not recommended. With the new ROIs, set the value of the Color property instead. For more information, see Version History.

Description

setColor(h,color) sets the color used to draw the ROI object h.

example

Examples

collapse all

Display an image. Draw a polygon on the image, specifying the location of five vertices.

imshow("gantrycrane.png")
h = impoly(gca,[188,30; 189,142; 93,141; 13,41; 14,29]);

Closed polygon drawn in blue over an image.

Set the color of the polygon to yellow.

setColor(h,"yellow");

Polygon color changed to yellow.

Input Arguments

collapse all

ROI object, specified as an imellipse, imfreehand, imline, impoint, impoly, or imrect object.

ROI color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short color name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • An 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], for example, [0.4 0.6 0.7].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and the hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Sample of the color red

"green""g"[0 1 0]"#00FF00"

Sample of the color green

"blue""b"[0 0 1]"#0000FF"

Sample of the color blue

"cyan" "c"[0 1 1]"#00FFFF"

Sample of the color cyan

"magenta""m"[1 0 1]"#FF00FF"

Sample of the color magenta

"yellow""y"[1 1 0]"#FFFF00"

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

This table lists the default color palettes for plots in the light and dark themes.

PalettePalette Colors

"gem" — Light theme default

Before R2025a: Most plots use these colors by default.

Sample of the "gem" color palette

"glow" — Dark theme default

Sample of the "glow" color palette

You can get the RGB triplets and hexadecimal color codes for these palettes using the orderedcolors and rgb2hex functions. For example, get the RGB triplets for the "gem" palette and convert them to hexadecimal color codes.

RGB = orderedcolors("gem");
H = rgb2hex(RGB);

Before R2023b: Get the RGB triplets using RGB = get(groot,"FactoryAxesColorOrder").

Example: "r"

Example: "green"

Example: [0 0.4470 0.7410]

Example: "#00FFFF"

Version History

Introduced in R2008a

collapse all

See Also

|