StackedLineChart - Stacked plot appearance and behavior - MATLAB (original) (raw)
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
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
_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. Thestackedplot
function plots each column of the value ofYData
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
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 Scheme | Examples |
---|---|
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
andTemp2
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
) or0
(false
). A value of "on"
is equivalent to true
, and "off"
is equivalent tofalse
. 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. Thestackedplot
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 aretbl1,tbl2,tbl3
, thenXVariable
can be"X"
if each table has a variable namedX
that provides _x_-values. However, iftbl1
has a variable namedX1
,tbl2
a variable namedX2
, andtbl3
a variable namedX3
, thenXVariable
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 ofStackedAxesProperties
objects. You can index intoAxesProperties
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 ofStackedLineProperties
objects. You can index intoLineProperties
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
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 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 the 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 |
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._ | ![]() |
"glow" — Dark theme default | ![]() |
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))
.
Example: "blue"
Example: [0 0 1]
Example: "#0000FF"
Markers
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 from0
toF
. 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 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: [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 from0
toF
. 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 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: [0.3 0.2 0.1]
Example: "green"
Example: "#D2F9A7"
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
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.
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 inDisplayVariables
. By default, the values are the same as the values in DisplayVariables
.
If you add a value, delete a value, or rearrange the values inDisplayVariables
, 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
) or0
(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
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
andbottom
elements define the distance from the lower left corner of the container to the lower left corner of the plot. - The
width
andheight
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 aTiledChartLayout
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
andbottom
elements define the distance from the lower left corner of the container to the lower left corner of the plot. - The
width
andheight
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 aTiledChartLayout
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 theInnerPosition
property.
Note
Setting this property has no effect when the parent container is aTiledChartLayout
object.
Position property to hold constant when adding, removing, or changing decorations, specified as one of the following values:
"outerposition"
— TheOuterPosition
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 theInnerPosition
property."innerposition"
— TheInnerPosition
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 theOuterPosition
property.
Note
Setting this property has no effect when the parent container is aTiledChartLayout
object.
Layout options, specified as a TiledChartLayoutOptions
orGridLayoutOptions
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 theTile
and TileSpan
properties on theTiledChartLayoutOptions
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.
This code places the chart c
in the third tile of the grid.
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 theTile
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.
To place the chart into a layout within an app, specify this property as aGridLayoutOptions
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
Parent/Child
Parent container, specified as a Figure
,Panel
, Tab
,TiledChartLayout
, or GridLayout
object.
Version History
Introduced in R2018b
Starting in R2020a, setting or getting ActivePositionProperty
is not recommended. Use the PositionConstraint
property instead.
There are no plans to remove ActivePositionProperty
at this time, but the property is no longer listed when you call the set
,get
, or properties
functions on the chart object.
To update your code, make these changes:
- Replace all instances of
ActivePositionProperty
withPositionConstraint
. - Replace all references to the
"position"
option with the"innerposition"
option.