Constant line appearance and behavior (2024)

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

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;

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.

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

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.

Horizontal alignment of the label with respect to the line, specified as one of the options in the table.

OptionDescription
'right'

Right side of the line.

Constant line appearance and behavior (1)

'left'

Left side of the line.

Constant line appearance and behavior (2)

'center'

Center of the line. For vertical lines, the label segments the line.

Constant line appearance and behavior (3)

Vertical alignment of the label with respect to the line, specified as one of the options in the table.

OptionDescription
'top'

Top of the line.

Constant line appearance and behavior (4)

'middle'

Middle of the line. For horizontal lines, the label segments the line.

Constant line appearance and behavior (5)

'bottom'

Bottom of the line.

Constant line appearance and behavior (6)

Label orientation, specified as 'aligned' or 'horizontal'. Examples are shown in the table.

OrientationDescription
'aligned'

Label has the same orientation as the line.

Constant line appearance and behavior (7)

'horizontal'

Label is horizontal, regardless of the line orientation.

Constant line appearance and behavior (8)

Color and Styling

expand all

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 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 hexadecimal color codes.

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

Constant line appearance and behavior (9)

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

Constant line appearance and behavior (10)

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

Constant line appearance and behavior (11)

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

Constant line appearance and behavior (12)

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

Constant line appearance and behavior (13)

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

Constant line appearance and behavior (14)

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

Constant line appearance and behavior (15)

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

Constant line appearance and behavior (16)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Constant line appearance and behavior (17)

[0.8500 0.3250 0.0980]"#D95319"

Constant line appearance and behavior (18)

[0.9290 0.6940 0.1250]"#EDB120"

Constant line appearance and behavior (19)

[0.4940 0.1840 0.5560]"#7E2F8E"

Constant line appearance and behavior (20)

[0.4660 0.6740 0.1880]"#77AC30"

Constant line appearance and behavior (21)

[0.3010 0.7450 0.9330]"#4DBEEE"

Constant line appearance and behavior (22)

[0.6350 0.0780 0.1840]"#A2142F"

Constant line appearance and behavior (23)

Example: 'g'

Example: [0.6 0.2 0.5]

Example: '#D2F9A7'

Line width, specified as a positive value in points.

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.

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

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, specified as an Axes object.

Identifiers

expand all

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

Move ConstantLine objects above or below other elements in a plot by setting the Layer property to "top" or "bottom".

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.

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.

Constant line appearance and behavior (24)

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)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Constant line appearance and behavior (2024)
Top Articles
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5634

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.