Constant line appearance and behavior
expand all in page
A constant line is a line that is graphed at a specified x- or y-value in Cartesian axes. The xline
and yline
functions create constant vertical and horizontal lines, respectively. You can modify the appearance and behavior of the constant line by changing ConstantLine
property values.
xl = xline(4);xl.LineWidth = 2;
Location
expand all
Value
— Location of constant line
scalar
Location of the constant line on the x- or y-axis, specified as a scalar. You can specify the value as a numeric, categorical, datetime
, or duration value.
Example
Create a constant line at x = 5.5. Then change the value to 7
.
xl = xline(5.5);xl.Value = 7;
InterceptAxis
— Intercept axis
'x'
| 'y'
Intercept axis, specified as 'x'
or 'y'
for a vertical line or horizontal line, respectively. A constant line with an x-intercept is a vertical line, whereas a constant line with a y-intercept is a horizontal line.
Layer
— Layer position
"bottom"
(default) | "top"
Since R2024a
Layer position, specified as "bottom"
or "top"
. A value of "bottom"
displays the ConstantLine
object under other items in the axes, such as lines or markers. A value of "top"
displays the ConstantLine
object on top of other items.
Passing a ConstantLine
object to the uistack
function has no effect on its stacking order, nor does reordering the Children
property of the axes.
Labels
expand all
Label
— Line label
''
(default) | character vector | cell array of character vectors | string array | numeric array
Line label, specified as a character vector, cell array of character vectors, string array, or numeric array. To create a multiline label, use a string array or a cell array of character vectors.
Example: "cutoff frequency"
Example: ["One row of text","A second row of text"]
Example: {'One row of text','A second row of text'}
To include special characters, such as superscripts, subscripts, Greek letters, or mathematical symbols, use TeX markup. For a list of supported markup, see the Interpreter property.
LabelHorizontalAlignment
— Horizontal alignment of label
'right'
(default) | 'left'
| 'center'
Horizontal alignment of the label with respect to the line, specified as one of the options in the table.
Option | Description | |
---|---|---|
'right' | Right side of the line. | |
'left' | Left side of the line. | |
'center' | Center of the line. For vertical lines, the label segments the line. |
LabelVerticalAlignment
— Vertical alignment of label
'top'
(default) | 'middle'
| 'bottom'
Vertical alignment of the label with respect to the line, specified as one of the options in the table.
Option | Description | |
---|---|---|
'top' | Top of the line. | |
'middle' | Middle of the line. For horizontal lines, the label segments the line. | |
'bottom' | Bottom of the line. |
LabelOrientation
— Label orientation
'aligned'
(default) | 'horizontal'
Label orientation, specified as 'aligned'
or 'horizontal'
. Examples are shown in the table.
Orientation | Description | |
---|---|---|
'aligned' | Label has the same orientation as the line. | |
'horizontal' | Label is horizontal, regardless of the line orientation. |
Color and Styling
expand all
Color
— Line color
[0.15 0.15 0.15]
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...
Line color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short 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 from0
toF
. 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 hexadecimal color codes.
Color Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|---|---|
"red" | "r" | [1 0 0] | "#FF0000" | |
"green" | "g" | [0 1 0] | "#00FF00" | |
"blue" | "b" | [0 0 1] | "#0000FF" | |
"cyan" | "c" | [0 1 1] | "#00FFFF" | |
"magenta" | "m" | [1 0 1] | "#FF00FF" | |
"yellow" | "y" | [1 1 0] | "#FFFF00" | |
"black" | "k" | [0 0 0] | "#000000" | |
"white" | "w" | [1 1 1] | "#FFFFFF" | |
"none" | 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.4470 0.7410] | "#0072BD" | |
[0.8500 0.3250 0.0980] | "#D95319" | |
[0.9290 0.6940 0.1250] | "#EDB120" | |
[0.4940 0.1840 0.5560] | "#7E2F8E" | |
[0.4660 0.6740 0.1880] | "#77AC30" | |
[0.3010 0.7450 0.9330] | "#4DBEEE" | |
[0.6350 0.0780 0.1840] | "#A2142F" |
Example: 'g'
Example: [0.6 0.2 0.5]
Example: '#D2F9A7'
LineWidth
— Line width
0.5
(default) | positive value
Line width, specified as a positive value in points.
Alpha
— Line transparency
0.7
(default) | scalar in range [0,1]
Line transparency, specified as a scalar in the range [0,1]
. A value of 1
is opaque and 0
is completely transparent. Values between 0
and 1
are semitransparent.
SeriesIndex
— Series index
"none"
(default) | positive whole number
Series index, specified as a positive whole number or "none"
. This property is useful for reassigning the colors and line styles of ConstantLine
objects so that they match other objects.
When the SeriesIndex
property is a number, MATLAB uses the number to calculate indices for assigning colors and line styles when you call the xline
or yline
functions. The indices refer to the rows of the arrays stored in the ColorOrder
and LineStyleOrder
properties of the axes. Any objects in the axes that have the same SeriesIndex
number will have the same color (and line style, if applicable).
A SeriesIndex
value of "none"
corresponds to a solid line with a neutral color that does not participate in the indexing scheme.
How Manually Setting Colors, Line Styles, or Markers Overrides SeriesIndex
Behavior
To manually control the color and line style, set the Color
and LineStyle
properties of the ConstantLine
object.
When you manually set these properties of an object, MATLAB disables automatic color and line style selection for that object and allows your selection to persist, regardless of the value of the SeriesIndex
property. The ColorMode
and LineStyleMode
properties indicate whether the colors and line styles have been set manually (by you) or automatically. For each of these mode properties, a value of "manual"
indicates manual selection, and "auto"
indicates automatic selection.
To enable automatic selection again, set the ColorMode
, LineStyleMode
, or both properties to "auto"
, and set the SeriesIndex
property to a positive whole number.
In some cases, MATLAB sets the SeriesIndex
property to 0
, which also disables automatic color selection.
Font
expand all
FontSize
— Font Size
positive number
Font size, specified as a positive number. The unit of measurement is points. The default font size depends on your operating system and locale.
Legend
expand all
Interactivity
expand all
Callbacks
expand all
Callback Execution Control
expand all
Parent/Child
expand all
Parent
— Parent
Axes
object (default)
Parent, specified as an Axes
object.
Identifiers
expand all
Type
— Type of graphics object
'constantline'
This property is read-only.
Type of graphics object, returned as 'constantline'
. Use this property to find all objects of a given type within a plotting hierarchy, for example, searching for the type using findobj.
Version History
Introduced in R2018b
expand all
R2024a: Layer reference lines in plots
Move ConstantLine
objects above or below other elements in a plot by setting the Layer property to "top"
or "bottom"
.
R2023b: Enable Automatic Color and Line Style Selection with the SeriesIndex
property
Set the SeriesIndex
property of a ConstantLine
object to control how the objects vary in color and line style. Changing the value of this property is useful when you want to match the colors and line styles of different objects in the axes.
R2020a: UIContextMenu
property is not recommended
Setting or getting UIContextMenu
property is not recommended. Instead, use the ContextMenu
property, which accepts the same type of input and behaves the same way as the UIContextMenu
property.
There are no plans to remove the UIContextMenu
property, but it is no longer listed when you call the set
, get
, or properties
functions on the ConstantLine
object.
See Also
xline | yline
Topics
- Access Property Values
- Graphics Object Properties
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office