Main Content

StackedLineChart Properties

Stacked plot appearance and behavior

StackedLineChart properties control the appearance and behavior of 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.

You can use dot notation to query and set properties.

T = readtable("outages.csv");
s = stackedplot(T);
c = s.Color;
s.Color = "red";

Table Data

expand all

Source table, specified as a table, timetable, cell array of tables, or cell array of timetables.

You can create a table from workspace variables using the table function, or you can import data as a table using the readtable function. You can create a timetable from workspace variables using the timetable function, or you can import data as a timetable using the readtimetable function.

Note

The property is ignored and read-only when the plotted data comes from an array.

Array Data

expand all

x-values, specified as a vector. The number of elements in the vector must equal the number of rows in the value of the YData property.

Note

The property is ignored and read-only when the plotted data comes from tables or timetables.

Example: [1:10]

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

y-values, specified as an array. The stackedplot function plots each column of the value of YData in its own y-axis.

Note

The property is ignored and read-only when the plotted data comes from a table or timetable.

Example: [1:10;5:5:50]

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Stacked Plot Display

expand all

Displayed variables for y-axes, specified using one of the indexing schemes from the table.

Note: If you create a stacked plot from multiple tables or timetables, then DisplayVariables can be only a string array, a cell array of character vectors, or a cell array whose elements are string arrays or cell arrays of character vectors.

Indexing SchemeExamples

Variable names:

  • A string array or a cell array of character vectors.

  • "A" — A variable called A

  • ["A","B"] or {'A','B'} — Two variables called A and B

Variable index (for single table or timetable only):

  • An index number that refers to the location of a variable in the table.

  • A vector of numbers.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [2 3] — The second and third variables from the table

  • [false false true] — The third variable

Variable type (for single table or timetable only):

  • A vartype subscript that selects variables of a specified type.

  • vartype("categorical") — All the variables containing categorical values

Variables specified in nested cell array:

  • A cell array that contains numeric arrays (for single table or timetable only).

  • A cell array that contains string arrays.

  • A cell array that contains cell arrays of character vectors.

  • {[1 2] 3} — The first and second variables plotted in one y-axis, and the third variable plotted in a second y-axis

  • {["A","B"],"C"} — Variables A and B plotted in one y-axis, and variable C plotted in a second y-axis

  • {{'A','B'},'C'} — Variables A and B plotted in one y-axis, and variable C plotted in a second y-axis

Example: s.DisplayVariables = [1 3 4] specifies the first, third, and fourth variables.

Example: s.DisplayVariables = {["Temp1","Temp2"],"Pressure"} uses a nested cell array to specify that Temp1 and Temp2 are plotted together.

Example: s.DisplayVariables = {{1,2},5} specifies variables by number and plots the first and second variables together.

Display of events, specified as "on" or "off", or as numeric or logical 1 (true) or 0 (false). A value of "on" is equivalent to true, and "off" is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

The events come from an event table that is attached to the input timetable. The stackedplot function plots events as vertical lines or shaded regions on the stacked plot. For information on event tables, see eventtable.

Flag for combining variables with matching names in the same y-axis, specified as a numeric or logical 1 (true) or 0 (false). Set this flag to false or 0 to plot variables from different inputs but with the same names in different y-axes.

Table variables that contain x-values, specified as a string array, character vector, cell array of character vectors, integer array, or logical array.

  • If the input is one table, then XVariable specifies one variable in the table.

  • If the inputs are multiple tables, then XVariable can specify either one variable that is present in all tables or a different variable in each table.

    For example, if the inputs are tbl1,tbl2,tbl3, then XVariable can be "X" if each table has a variable named X that provides x-values. However, if tbl1 has a variable named X1, tbl2 a variable named X2, and tbl3 a variable named X3, then XVariable is ["X1","X2","X3"].

Note

The property is ignored and read-only when the plotted data come from an array or a timetable.

Minimum and maximum x-axis limits, specified as a two-element vector of the form [min max], where max is greater than min. You can specify the limits as numeric, categorical, datetime, or duration values. However, the type of values that you specify must match the type of values along the axis.

You can specify both limits or you can specify one limit and let the axes automatically calculate the other. For an automatically calculated minimum or maximum limit, use -inf or inf, respectively.

Example: s.XLimits = [0 100]

Example: s.XLimits = [-inf 100]

Example: s.XLimits = [0 inf]

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | datetime | duration

Properties of the y-axes, specified as an array of StackedAxesProperties objects. You can index into AxesProperties to change the y-axis properties for one variable in the stacked plot. For more information, see StackedAxesProperties Properties.

Example: s.AxesProperties(2).YLimits = [0 10] specifies limits for the second plot in the stacked plot. The other plots are unaltered.

Properties of lines, specified as an array of StackedLineProperties objects. You can index into LineProperties to change the properties of a line for one variable in the stacked plot. For more information, see StackedLineProperties Properties.

Example: s.LineProperties(3).Color = "red" changes the line color of the third plot in the stacked plot. The other plots are unaltered.

Display of grid lines, specified as "on" or "off", or as numeric or logical 1 (true) or 0 (false). A value of "on" is equivalent to true, and "off" is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

Line

expand all

Line color, specified as 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.

  • 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"

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 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"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Example: "blue"

Example: [0 0 1]

Example: "#0000FF"

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

Line StyleDescriptionResulting 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 lineNo line

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.

Markers

expand all

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.

MarkerDescriptionResulting 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 markersNot applicable

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

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.

  • 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 character vector or a string scalar 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. Thus, 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"

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 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"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Example: [0.5 0.5 0.5]

Example: "blue"

Example: "#D2F9A7"

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.

  • 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 character vector or a string scalar 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. Thus, 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"

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 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"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Example: [0.3 0.2 0.1]

Example: "green"

Example: "#D2F9A7"

Font

expand all

Font name, specified as a supported font name or "FixedWidth". To display and print text properly, you must choose a font that your system supports. The default font depends on your operating system and locale.

To use a fixed-width font that looks good in any locale, use "FixedWidth". The fixed-width font relies on the root FixedWidthFontName property. Setting the root FixedWidthFontName property causes an immediate update of the display to use the new font.

Font size, specified as a scalar numeric value. The font size affects the title, axis labels, and tick labels. It also affects any legends associated with the axes. The font size is measured in points.

Example: s.FontSize = 12

Labels

expand all

Title of the stacked plot, specified as a character vector, string scalar, numeric scalar, string array, numeric array, cell array, or categorical array.

If the value of Title is an array, then the elements of the array are stacked vertically and displayed as the title. If the value is a cell array, then its elements can be character vectors, strings, or numbers.

Alternatively, use the title function to add a title.

title("My Title")

Example: s.Title = "A Title";

Example: s.Title = 137

Example: s.Title = ["Stacked plot",string(datetime("now"))];

Example: s.Title = {"Stacked plot",137};

Labels for the stacked y-axes values, specified as a cell array of character vectors or a string array. Specify one label for each value in DisplayVariables. By default, the values are the same as the values in DisplayVariables.

If you add a value, delete a value, or rearrange the values in DisplayVariables, then this property updates accordingly to maintain the pairings of values and labels.

Example: s.DisplayLabels = ["Temperature","Humidity","Pressure"]

Label for x-axis, specified as a character vector, string scalar, numeric scalar, string array, numeric array, cell array, or categorical array.

If the value of XLabel is an array, then the elements of the array are stacked vertically and displayed as the x-axis label. If the value is a cell array, then its elements can be character vectors, strings, or numbers.

Alternatively, use the xlabel function to add an x-axis label.

xlabel("My x-Axis Label")

Example: s.XLabel = "An x-axis Label";

Example: s.XLabel = 137

Example: s.XLabel = ["An x-axis Label",string(datetime("now"))];

Example: s.XLabel = {"An x-axis Label",137};

Labels for the inputs in the legend, specified as a string array or a cell array of character vectors. Each label corresponds to an input table or timetable. By default, the labels in the legend are the names of the input tables or timetables.

Example: s.LegendLabels = ["Table1","Table2","Table3"]

Orientation of the labels in the legend, specified as "horizontal" or "vertical". The "horizontal" orientation lists labels horizontally in the legend, while the "vertical" orientation lists labels vertically in the legend.

Legend visibility, specified as "on" or "off", or as a numeric or logical 1 (true) or 0 (false). If LegendVisible is "off", then the legend is not displayed.

The default value is:

  • "off" if the input is a single table or timetable

  • "on" if the inputs are multiple tables or timetables

A value of "on" is equivalent to true, and "off" is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

Position

expand all

Outer size and location of the plot within the parent container (typically a figure, panel, or tab), specified as a four-element vector of the form [left bottom width height].

  • The left and bottom elements define the distance from the lower left corner of the container to the lower left corner of the plot.

  • The width and height elements are the width and height of the rectangle that encloses the plot and the axes, including decorations such as the title and axis labels.

The default value of [0 0 1 1] covers the whole interior of the container. The units are normalized relative to the size of the container. To change the units, set the Units property.

Note

Setting this property has no effect when the parent container is a TiledChartLayout object.

Inner size and location of the plot within the parent container (typically a figure, panel, or tab) specified as a four-element vector of the form [left bottom width height].

  • The left and bottom elements define the distance from the lower left corner of the container to the lower left corner of the plot.

  • The width and height elements are the width and height of the rectangle that encloses the plot and the axes, excluding decorations such as the title and axis labels.

Note

Setting this property has no effect when the parent container is a TiledChartLayout object.

Inner size and location of the plot within the parent container (typically a figure, panel, or tab) returned as a four-element vector of the form [left bottom width height]. This property is equivalent to the InnerPosition property.

Note

Setting this property has no effect when the parent container is a TiledChartLayout object.

Position property to hold constant when adding, removing, or changing decorations, specified as one of the following values:

  • "outerposition" — The OuterPosition property remains constant when you add, remove, or change decorations such as a title or an axis label. If any positional adjustments are needed, MATLAB adjusts the InnerPosition property.

  • "innerposition" — The InnerPosition property remains constant when you add, remove, or change decorations such as a title or an axis label. If any positional adjustments are needed, MATLAB adjusts the OuterPosition property.

Note

Setting this property has no effect when the parent container is a TiledChartLayout object.

Position units, specified as one of these values.

UnitsDescription
"normalized" (default)Normalized with respect to the container, which is typically the figure or a panel. The lower left corner of the container maps to (0,0) and the upper right corner maps to (1,1).
"inches"Inches.
"centimeters"Centimeters.
"characters"

Based on the default uicontrol font of the graphics root object:

  • Character width = width of letter x.

  • Character height = distance between the baselines of two lines of text.

"points"Typography points. One point equals 1/72 inch.
"pixels"

Pixels.

Starting in R2015b, distances in pixels are independent of your system resolution on Windows® and Macintosh systems.

  • On Windows systems, a pixel is 1/96th of an inch.

  • On Macintosh systems, a pixel is 1/72nd of an inch.

  • On Linux® systems, the size of a pixel is determined by your system resolution.

When specifying the units as a Name,Value pair during object creation, you must set the Units property before specifying the properties that you want to use these units, such as Position.

Layout options, specified as a TiledChartLayoutOptions or GridLayoutOptions object. This property is useful when the chart is either in a tiled chart layout or a grid layout.

To position the chart within the grid of a tiled chart layout, set the Tile and TileSpan properties on the TiledChartLayoutOptions object. For example, consider a 3-by-3 tiled chart layout. The layout has a grid of tiles in the center, and four tiles along the outer edges. In practice, the grid is invisible and the outer tiles do not take up space until you populate them with axes or charts.

Diagram of a 3-by-3 tiled chart layout.

This code places the chart c in the third tile of the grid.

c.Layout.Tile = 3;

To make the chart span multiple tiles, specify the TileSpan property as a two-element vector. For example, this chart spans 2 rows and 3 columns of tiles.

c.Layout.TileSpan = [2 3];

To place the chart in one of the surrounding tiles, specify the Tile property as "north", "south", "east", or "west". For example, setting the value to "east" places the chart in the tile to the right of the grid.

c.Layout.Tile = "east";

To place the chart into a layout within an app, specify this property as a GridLayoutOptions object. For more information about working with grid layouts in apps, see uigridlayout.

If the chart is not a child of either a tiled chart layout or a grid layout (for example, if it is a child of a figure or panel) then this property is empty and has no effect.

Interactivity

expand all

State of visibility, specified as "on" or "off", or as numeric or logical 1 (true) or 0 (false). A value of "on" is equivalent to true, and "off" is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • "on" — Display the object.

  • "off" — Hide the object without deleting it. You still can access the properties of an invisible object.

Parent/Child

expand all

Parent container, specified as a Figure, Panel, Tab, TiledChartLayout, or GridLayout object.

Visibility of the object handle in the Children property of the parent, specified as one of these values:

  • "on" — Object handle is always visible.

  • "off" — Object handle is invisible at all times. This option is useful for preventing unintended changes by another function. Set HandleVisibility to "off" to temporarily hide the handle during the execution of that function.

  • "callback" — Object handle is visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line. This option blocks access to the object at the command line, but permits callback functions to access it.

If the object is not listed in the Children property of the parent, then functions that obtain object handles by searching the object hierarchy or querying handle properties cannot return it. Examples of such functions include the get, findobj, gca, gcf, gco, newplot, cla, clf, and close functions.

Hidden object handles are still valid. Set the root ShowHiddenHandles property to "on" to list all object handles regardless of their HandleVisibility property setting.

Version History

Introduced in R2018b

expand all