Rectangle appearance and behavior
Rectangle properties control the appearance and behavior of a rectangle object. By changing property values, you can modify certain aspects of the rectangle. Use dot notation to query and set properties.
h = rectangle; w = h.LineWidth; h.LineWidth = 3;
Color and Styling
EdgeColor — Outline color
[0 0 0] (default) | RGB triplet | hexadecimal color code |
'b' | ...
Outline color, specified as an RGB triplet, a hexadecimal color code, a color name, or a
short name. The default value of
[0 0 0] corresponds to black.
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
F. The values are not case sensitive. Therefore, the color codes
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
|Color Name||Short Name||RGB Triplet||Hexadecimal Color Code||Appearance|
|Not applicable||Not applicable||Not applicable||No color|
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
|RGB Triplet||Hexadecimal Color Code||Appearance|
[0 0 1]
EdgeColorMode — Control how
EdgeColor is set
"auto" (default) |
Control how the
EdgeColor property is set, specified as one of these values:
"auto"— MATLAB controls the value of the
EdgeColorproperty by using the
SeiesIndexproperty of the
Rectangleobject and the
ColorOrderproperty of the axes.
"manual"— You set the value of the
EdgeColorproperty directly, or indirectly as a function argument when you create the
If you change the value of the
EdgeColor property manually,
MATLAB changes the value of the
EdgeColorMode property to
LineWidth — Line width
0.5 (default) | positive value
Line width, specified as a positive value in point units.
SeriesIndex — Series index
"none" (default) | positive whole number
Series index, specified as positive whole number or
property is useful for reassigning the outline colors of
objects so that they match the colors of other objects.
SeriesIndex value is a number, MATLAB uses that number to calculate an index for assigning the outline color when you
rectangle function. The index refers to the rows of the array
stored in the
ColorOrder property of the axes. Any objects in the axes
that have the same
SeriesIndex number will have the same color.
SeriesIndex value of
"none" corresponds to a
neutral color that does not participate in the indexing scheme.
How Manual Color Assignment Overrides
To manually control the outline color, set the
Rectangle object to a color value, such as a color name or RGB
When you manually set the outline color of a rectangle, MATLAB does not use automatic color selection for that object, and it allows your
color to persist, regardless of the value of the
EdgeColorMode property indicates whether the color has been set
manually (by you) or automatically. A value of
"manual" indicates manual
selection, and a value of
"auto" indicates automatic selection.
To enable automatic selection, set the
SeriesIndex property to a
positive whole number, and set the
EdgeColorMode property to
In some cases, MATLAB sets the
SeriesIndex property to
which also disables automatic color selection.
Curvature — Amount of horizontal and vertical curvature
[0 0] (default) | two-element vector | scalar
Amount of horizontal and vertical curvature, specified as a two element vector of the
[x y] or a scalar value. Use this property to vary the shape of the
rectangle from rectangular to ellipsoidal. The horizontal curvature is the fraction of the
width that is curved along the top and bottom edges. The vertical curvature is the fraction of
the height that is curved along the left and right edges.
To use different horizontal and vertical curvatures, specify a two-element vector of the form
[x y]. The
xelement determines the horizontal curvature and the
yelement determines the vertical curvature. Specify
yas values between 0 (no curvature) and 1 (maximum curvature). For example, a value of
[0 0]creates a rectangle with square edges and value of
[1 1]creates an ellipse.
To use the same curvature for the horizontal and vertical edges, specify a scalar value in the range
[0,1]. The shorter dimension determines the length of the curvature.
Position — Size and location of rectangle
[0 0 1 1] (default) | four-element vector
Size and location of the rectangle, specified as a four-element vector of the form
[x y width height]. Specify the values in data units. The
y elements define the coordinate for the
lower-left corner of the rectangle. The
elements define the dimensions of the rectangle.
[0.5 0.5 0.3 0.4]
Callback Execution Control
Version HistoryIntroduced before R2006a
R2023b: Control Automatic Color Selection with the
Rectangle objects vary in color by setting the
SeriesIndex property. This property is useful when you want to
match the colors of different objects in the axes.
UIContextMenu property is not recommended
Setting or getting
UIContextMenu property is not recommended. Instead,
property, which accepts the same type of input and behaves the same way as the
There are no plans to remove the
UIContextMenu property, but it is no
longer listed when you call the
properties functions on the