StackedLineProperties - Appearance and behavior of individual lines in stacked plot - MATLAB (original) (raw)

StackedLineProperties Properties

Appearance and behavior of individual lines in stacked plot

StackedLineProperties properties control the appearance and behavior of individual lines in a stacked plot. In a stacked plot, you can plot the variables of a table or timetable, or the columns of a matrix, in separate_y_-axes, stacked vertically. By changing property values, you can modify certain aspects of the stacked plot.

The stackedplot function returns aStackedLineChart object. In turn, this object has an array ofStackedLineProperties objects, named LineProperties. To set properties of an individual line, index into LineProperties and access properties of the corresponding object.

You can use dot notation to query and set properties. For example, change the third plot to a scatter plot using its PlotType property.

T = readtable("outages.csv"); s = stackedplot(T); c = s.LineProperties(3).PlotType s.LineProperties(3).PlotType = "scatter";

If you plot multiple lines in one _y_-axis, then you can specify different line property values for each line in that _y_-axis. For example, plot one table variable in the first _y_-axis of a stacked plot and two table variables in the second _y_-axis. Specify a different plot type for each line in the second _y_-axis by specifyings.LineProperties(2).PlotType as a string array.

T = array2table(magic(9)); s = stackedplot(T,{"Var1",["Var2" "Var3"]}); s.LineProperties(1).PlotType = "stairs"; s.LineProperties(2).PlotType = ["scatter","plot"];

Line Properties

expand all

Line color, specified as an RGB triplet, a three-column matrix of RGB triplets, a hexadecimal color code, or one of the color options listed in the first table.

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

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 Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"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
"none" Not applicable Not applicable Not applicable No color

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

Palette Palette 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").

Before R2024a: Get the hexadecimal color codes using H = compose("#%02X%02X%02X",round(RGB*255)).

Note: If you plot multiple lines in one_y_-axis, then you can specify Color as a three-column matrix of RGB triplets that specify a different color for each line. For example, if there are two lines in a _y_-axis. then you can specifyColor as [1 0 0] (to turn both lines red) or as[1 0 0; 0 0 1] (to turn the first line red and the second line blue).

Example: s.LineProperties(1).Color = "blue";

Example: s.LineProperties(2).Color = [0 0 1];

Example: s.LineProperties(3).Color = "#0000FF";

Example: s.LineProperties(4).Color = [1 0 0; 0 0 1]; if the fourth_y_-axis has two lines.

Line style, specified as one of the options listed in this table.

Line Style Description Resulting Line
"-" Solid line Sample of solid line
"--" Dashed line Sample of dashed line
":" Dotted line Sample of dotted line
"-." Dash-dotted line Sample of dash-dotted line, with alternating dashes and dots
"none" No line No line

Note: If you plot multiple lines in one_y_-axis, then you can specify LineStyle as a string array or cell array of character vectors that specify a different option for each line.

Example: s.LineProperties(1).LineStyle = "-";

Example: s.LineProperties(3).LineStyle = ["-",":"]; if the third_y_-axis has two lines.

Line width, specified as a positive value in points, where 1 point = 1/72 of an inch. If the line has markers, then the line width also affects the marker edges.

The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

Note: If you plot multiple lines in one_y_-axis, then you can specify LineWidth as a vector that specifies a different width for each line.

Example: s.LineProperties(1).LineWidth = 1.0;

Example: s.LineProperties(3).LineWidth = [1.5 3.0]; if the third_y_-axis has two lines.

Marker symbol, specified as one of the values listed in this table. By default, the object does not display markers. Specifying a marker symbol adds markers at each data point or vertex.

Marker Description Resulting Marker
"o" Circle Sample of circle marker
"+" Plus sign Sample of plus sign marker
"*" Asterisk Sample of asterisk marker
"." Point Sample of point marker
"x" Cross Sample of cross marker
"_" Horizontal line Sample of horizontal line marker
"|" Vertical line Sample of vertical line marker
"square" Square Sample of square marker
"diamond" Diamond Sample of diamond marker
"^" Upward-pointing triangle Sample of upward-pointing triangle marker
"v" Downward-pointing triangle Sample of downward-pointing triangle marker
">" Right-pointing triangle Sample of right-pointing triangle marker
"<" Left-pointing triangle Sample of left-pointing triangle marker
"pentagram" Pentagram Sample of pentagram marker
"hexagram" Hexagram Sample of hexagram marker
"none" No markers Not applicable

Note: If you plot multiple lines in one_y_-axis, then you can specify Marker as a string array or cell array of character vectors that specify a different marker for each line.

Example: s.LineProperties(1).Marker = "+";

Example: s.LineProperties(3).Marker = ["^","v"]; if the third_y_-axis has two lines.

Marker size, specified as a positive value in points, where 1 point = 1/72 of an inch.

Note: If you plot multiple lines in one_y_-axis, then you can specify MarkerSize as a vector of positive values that specify a different marker size for each line.

Example: s.LineProperties(1).MarkerSize = 3.0;

Example: s.LineProperties(3).MarkerSize = [10 16]; if the third_y_-axis has two lines.

Marker outline color, specified as "none", an RGB triplet, a hexadecimal color code, or one of the color options listed in the first table.

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

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 Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"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
"none" Not applicable Not applicable Not applicable No color

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

Palette Palette 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").

Before R2024a: Get the hexadecimal color codes using H = compose("#%02X%02X%02X",round(RGB*255)).

Note: If you plot multiple lines in one_y_-axis, then you can specify MarkerEdgeColor as a three-column matrix of RGB triplets that specify a different marker outline color for each line. For example, if there are two lines in a _y_-axis. then you can specify MarkerEdgeColor as [1 0 0] (to outline markers for both lines with red) or as [1 0 0; 0 0 1] (to outline markers for the first line with red and markers for the second line with blue).

Example: s.LineProperties(1).MarkerEdgeColor = "blue";

Example: s.LineProperties(2).MarkerEdgeColor = [0 0 1];

Example: s.LineProperties(3).MarkerEdgeColor = "#0000FF";

Example: s.LineProperties(4).MarkerEdgeColor = [1 0 0; 0 0 1]; if the fourth _y_-axis has two lines.

Marker fill color, specified as "none", an RGB triplet, a hexadecimal color code, or one of the color options listed in the first table.

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

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 Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"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
"none" Not applicable Not applicable Not applicable No color

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

Palette Palette 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").

Before R2024a: Get the hexadecimal color codes using H = compose("#%02X%02X%02X",round(RGB*255)).

Note: If you plot multiple lines in one_y_-axis, then you can specify MarkerFaceColor as a three-column matrix of RGB triplets that specify a different marker fill color for each line. For example, if there are two lines in a _y_-axis. then you can specify MarkerFaceColor as [1 0 0] (to fill markers for both lines with red) or as [1 0 0; 0 0 1] (to fill markers for the first line with red and markers for the second line with blue).

Example: s.LineProperties(1).MarkerFaceColor = "blue";

Example: s.LineProperties(2).MarkerFaceColor = [0 0 1];

Example: s.LineProperties(3).MarkerFaceColor = "#0000FF";

Example: s.LineProperties(4).MarkerFaceColor = [1 0 0; 0 0 1]; if the fourth _y_-axis has two lines.

Plot type, specified as "plot", "stairs","scatter", or a string array or cell array of character vectors.

If you plot multiple lines in one _y_-axis, then you can specify a different plot type for each line by specifying PlotType as a string array or cell array of character vectors.

Example: s.LineProperties(1).PlotType = "scatter";

Example: s.LineProperties(3).PlotType = ["scatter","stairs"]; if the third _y_-axis has two lines.

Version History

Introduced in R2018b