stackedplot
Stacked plot of several variables with common x-axis
Syntax
Description
Table and Timetable Data
stackedplot(
plots the variables of a
table or timetable in a stacked plot, up to a maximum of 25 variables. The function plots
the variables in separate y-axes, stacked vertically. The variables
share a common x-axis.tbl
)
If
tbl
is a table, thenstackedplot
plots the variables against row numbers.If
tbl
is a timetable, thenstackedplot
plots the variables against row times.If
tbl
is a timetable with an attached event table, thenstackedplot
also plots events as vertical lines or shaded regions. (since R2023b)
The stackedplot
function plots all the numeric, logical,
categorical, datetime, and duration variables of tbl
, and ignores table
variables having any other data type.
Vector and Matrix Data
stackedplot(
plots the columns of
Y
)Y
versus their row number. The x-axis scale
ranges from 1 to the number of rows in Y
.
Additional Options
stackedplot(___,
sets
the line style, marker symbol, and color. You can use this syntax with the input arguments
of any of the previous syntaxes.LineSpec
)
stackedplot(___,"XVariable",
specifies table variables that provide the x-values for the stacked
plot.xvar
)
This syntax is supported only when the inputs are tables.
stackedplot(___,"CombineMatchingNames",false)
plots
variables from different inputs but with the same names in different
y-axes. The default behavior when you do not specify the
CombineMatchingNames
name-value argument is to plot them in the same
y-axis.
This syntax is supported only when the inputs are multiple tables or multiple timetables.
stackedplot(___,
sets
properties for the stacked plot using one or more name-value arguments. For a list of the
properties, see StackedLineChart Properties. Name-value argument settings apply to all the plots in the stacked
plot.Name,Value
)
stackedplot(
creates
the stacked plot in the figure, panel, or tab specified by parent
,___)parent
. The
option parent
can precede any of the input argument combinations in the
previous syntaxes.
s = stackedplot(___)
returns a StackedLineChart Properties object. You can use s
to change
properties of the stacked plot after creating it. The output s
is also
a standalone visualization
that works independently from other charts.
Examples
Plot Timetable Variables
Read data from a spreadsheet to a timetable. (Read any text data it contains into string arrays). The first variable that contains dates and times, OutageTime
, provides the row times for the timetable. Display the first five rows.
tbl = readtimetable("outages.csv","TextType","string"); head(tbl,5)
OutageTime Region Loss Customers RestorationTime Cause ________________ ___________ ______ __________ ________________ _________________ 2002-02-01 12:18 "SouthWest" 458.98 1.8202e+06 2002-02-07 16:50 "winter storm" 2003-01-23 00:49 "SouthEast" 530.14 2.1204e+05 NaT "winter storm" 2003-02-07 21:15 "SouthEast" 289.4 1.4294e+05 2003-02-17 08:14 "winter storm" 2004-04-06 05:44 "West" 434.81 3.4037e+05 2004-04-06 06:10 "equipment fault" 2002-03-16 06:18 "MidWest" 186.44 2.1275e+05 2002-03-18 23:23 "severe storm"
Sort the timetable so that its row times are in order. The row times of a timetable do not need to be in order. However, if you use the row times as the x-axis of a plot, then it is better to ensure the timetable is sorted by its row times.
tbl = sortrows(tbl); head(tbl,5)
OutageTime Region Loss Customers RestorationTime Cause ________________ ___________ ______ __________ ________________ ______________ 2002-02-01 12:18 "SouthWest" 458.98 1.8202e+06 2002-02-07 16:50 "winter storm" 2002-03-05 17:53 "MidWest" 96.563 2.8666e+05 2002-03-10 14:41 "wind" 2002-03-16 06:18 "MidWest" 186.44 2.1275e+05 2002-03-18 23:23 "severe storm" 2002-03-26 01:59 "MidWest" 388.04 5.6422e+05 2002-03-28 19:55 "winter storm" 2002-04-20 16:46 "MidWest" 23141 NaN NaT "unknown"
Create a stacked plot of data from tbl
. The row times, OutageTime
, provide the values along the x-axis. The stackedplot
function plots the values from the Loss
, Customers
, and RestorationTime
variables, with each variable plotted along its own y-axis. However, the plot does not include the Region
and Cause
variables because they contain data that cannot be plotted.
stackedplot(tbl)
Plot Events
Since R2023b
Plot events from an event table that is attached to a timetable. The result is a stacked plot of the timetable variables with events plotted as vertical lines or shaded regions. For more information about event tables, see eventtable
.
First, import a timetable and an event table from a sample MAT-file. Display the timetable, which has a list of weather conditions over a span of two weeks in November 2022.
load weatherEvents.mat
weatherData
weatherData=15×2 timetable
Time Temperature Humidity
___________ ___________ ________
01-Nov-2022 36 45
02-Nov-2022 31 76
03-Nov-2022 37 43
04-Nov-2022 36 46
05-Nov-2022 38 72
06-Nov-2022 32 54
07-Nov-2022 35 50
08-Nov-2022 34 45
09-Nov-2022 32 72
10-Nov-2022 30 58
11-Nov-2022 39 54
12-Nov-2022 34 58
13-Nov-2022 31 73
14-Nov-2022 40 78
15-Nov-2022 34 66
Next, display the event table. It has a list of storms that occurred in November 2022 and their durations.
weatherEvents
weatherEvents = 4x3 eventtable
Event Labels Variable: EventType
Event Lengths Variable: EventLength
Time EventType EventLength Precipitation (mm)
___________ _________ ___________ __________________
03-Nov-2022 Hail 1.2 hr 12.7
05-Nov-2022 Rain 36 hr 114.3
10-Nov-2022 Snow 18 hr 25.4
14-Nov-2022 Rain 20 hr 177.8
Then, attach the event table to the timetable. The event table becomes a property of the timetable. When you display the timetable, you can also see the event labels.
weatherData.Properties.Events = weatherEvents
weatherData=15×2 timetable
Time Temperature Humidity
___________ ___________ ________
01-Nov-2022 36 45
02-Nov-2022 31 76
Hail 03-Nov-2022 37 43
04-Nov-2022 36 46
Rain 05-Nov-2022 38 72
Rain 06-Nov-2022 32 54
07-Nov-2022 35 50
08-Nov-2022 34 45
09-Nov-2022 32 72
Snow 10-Nov-2022 30 58
11-Nov-2022 39 54
12-Nov-2022 34 58
13-Nov-2022 31 73
Rain 14-Nov-2022 40 78
15-Nov-2022 34 66
Create a stacked plot. The shaded regions indicate when the storms listed in the attached event table occurred.
stackedplot(weatherData)
To hide the events, use the EventsVisible
name-value argument.
stackedplot(weatherData,EventsVisible="off")
Plot Multiple Timetables
Load two timetables from the sample MAT-files, indoors
and outdoors
. Then display the first three rows of each timetable.
load indoors.mat load outdoors.mat head(indoors,3)
Time Humidity AirQuality ___________________ ________ __________ 2015-11-15 00:00:24 36 80 2015-11-15 01:13:35 36 80 2015-11-15 02:26:47 37 79
head(outdoors,3)
Time Humidity TemperatureF PressureHg ___________________ ________ ____________ __________ 2015-11-15 00:00:24 49 51.3 29.61 2015-11-15 01:30:24 48.9 51.5 29.61 2015-11-15 03:00:24 48.9 51.5 29.61
Create a stacked plot of the data in indoors
and outdoors
. When you create a stacked plot from multiple tables or timetables:
The legend displays the color associated with each table or timetable.
Variables that have the same names but that come from different tables or timetables are plotted in the same y-axis. For example, this call to
stackedplot
plots theHumidity
variables fromindoors
andoutdoors
in the same y-axis.
stackedplot(indoors,outdoors)
Combine and Separate Variables with Matching Names
Load two timetables from the sample MAT-files, indoors
and outdoors
. Both timetables have a variable named Humidity
. Make a stacked plot from the two Humidity
variables. The colors in the legend show which variables come from which timetable.
load indoors.mat load outdoors.mat head(indoors,5)
Time Humidity AirQuality ___________________ ________ __________ 2015-11-15 00:00:24 36 80 2015-11-15 01:13:35 36 80 2015-11-15 02:26:47 37 79 2015-11-15 03:39:59 37 82 2015-11-15 04:53:11 36 80
head(outdoors,5)
Time Humidity TemperatureF PressureHg ___________________ ________ ____________ __________ 2015-11-15 00:00:24 49 51.3 29.61 2015-11-15 01:30:24 48.9 51.5 29.61 2015-11-15 03:00:24 48.9 51.5 29.61 2015-11-15 04:30:24 48.8 51.5 29.61 2015-11-15 06:00:24 48.7 51.5 29.6
stackedplot(indoors,outdoors,"Humidity")
The syntax stackedplot(indoors,outdoors,"Humidity")
is equivalent to the syntax stackedplot(indoors,outdoors,"Humidity","CombineMatchingNames",true)
. By default, variables that have matching names but come from different inputs are plotted in the same y-axis.
To plot the two Humidity
variables in different y-axes, specify the "CombineMatchingNames",false
name-value argument.
stackedplot(indoors,outdoors,"Humidity","CombineMatchingNames",false)
Specify Variables
Create a table from patient data. Display the first three rows.
tbl = readtable("patients.xls","TextType","string"); head(tbl,3)
LastName Gender Age Location Height Weight Smoker Systolic Diastolic SelfAssessedHealthStatus __________ ________ ___ ___________________________ ______ ______ ______ ________ _________ ________________________ "Smith" "Male" 38 "County General Hospital" 71 176 true 124 93 "Excellent" "Johnson" "Male" 43 "VA Hospital" 69 163 false 109 77 "Fair" "Williams" "Female" 38 "St. Mary's Medical Center" 64 131 false 125 83 "Good"
Plot only four of the variables from the table.
stackedplot(tbl,["Height","Weight","Systolic","Diastolic"])
Reorder Variables
Read a timetable from file and display its first three rows.
tbl = readtimetable("outages.csv","TextType","string"); tbl = sortrows(tbl); head(tbl,3)
OutageTime Region Loss Customers RestorationTime Cause ________________ ___________ ______ __________ ________________ ______________ 2002-02-01 12:18 "SouthWest" 458.98 1.8202e+06 2002-02-07 16:50 "winter storm" 2002-03-05 17:53 "MidWest" 96.563 2.8666e+05 2002-03-10 14:41 "wind" 2002-03-16 06:18 "MidWest" 186.44 2.1275e+05 2002-03-18 23:23 "severe storm"
Reorder the variables by specifying them in an order that differs from their order in the table. For example, RestorationTime
is the last variable in the timetable that can be plotted. By default, stackedplot
places it at the bottom of the plot. But you can reorder the variables to put RestorationTime
at the top.
stackedplot(tbl,["RestorationTime","Loss","Customers"])
There are also other ways to reorder the variables.
Specify them by their numeric order in the table:
stackedplot(tbl,[4 2 3]);
Return a
StackedLineChart
object and reorder the values in itsDisplayVariables
property:
s = stackedplot(tbl); s.DisplayVariables = ["RestorationTime","Loss","Customers"]
Plot Columns of Matrix
Create a numeric matrix and a numeric vector.
X = [0:4:20]
X = 1×6
0 4 8 12 16 20
Y = randi(100,6,3)
Y = 6×3
82 28 96
91 55 49
13 96 81
92 97 15
64 16 43
10 98 92
Create a stacked plot using X
and Y
.
stackedplot(X,Y)
Specify Title and Labels Using Name-Value Arguments
Load a timetable that has a set of weather measurements. Display its first three rows.
load outdoors
outdoors(1:3,:)
ans=3×3 timetable
Time Humidity TemperatureF PressureHg
___________________ ________ ____________ __________
2015-11-15 00:00:24 49 51.3 29.61
2015-11-15 01:30:24 48.9 51.5 29.61
2015-11-15 03:00:24 48.9 51.5 29.61
Create a stacked plot. Specify the title and labels for the y-axes using name-value arguments. You can use name-value arguments to change any properties from their defaults values. (Also note that you can specify the degree symbol using char(176)
.)
degreeSymbol = char(176); newYlabels = ["RH (%)","T (" + degreeSymbol + "F)","P (in Hg)"]; stackedplot(outdoors,"Title","Weather Data","DisplayLabels",newYlabels)
Specify Legend for Multiple Timetables
Load two timetables from the sample MAT-files, indoors
and outdoors
.
load indoors.mat load outdoors.mat head(indoors,3)
Time Humidity AirQuality ___________________ ________ __________ 2015-11-15 00:00:24 36 80 2015-11-15 01:13:35 36 80 2015-11-15 02:26:47 37 79
head(outdoors,3)
Time Humidity TemperatureF PressureHg ___________________ ________ ____________ __________ 2015-11-15 00:00:24 49 51.3 29.61 2015-11-15 01:30:24 48.9 51.5 29.61 2015-11-15 03:00:24 48.9 51.5 29.61
When you create a stacked plot with multiple tables or timetables, it includes a legend. By default, the legend uses the names of the inputs as labels. But you can specify the labels and the orientation of the labels in the legend.
stackedplot(indoors,outdoors,"LegendLabels",["Inside Readings","Outside Readings"],... "LegendOrientation","vertical")
Also, you can hide the legend.
stackedplot(indoors,outdoors,"LegendVisible","off")
Change Properties of Lines and Axes
The stackedplot
function returns a StackedLineChart
object. You can use it to set the same line and axis properties for all plots, or to set different property values for individual plots. In this example, first change the line widths for all plots in a stacked plot. Then, use the PlotType
property of individual plots, so that the stacked plot has a line plot, scatter plot, and stair plot.
Load a timetable that has a set of weather measurements.
load outdoors
outdoors(1:3,:)
ans=3×3 timetable
Time Humidity TemperatureF PressureHg
___________________ ________ ____________ __________
2015-11-15 00:00:24 49 51.3 29.61
2015-11-15 01:30:24 48.9 51.5 29.61
2015-11-15 03:00:24 48.9 51.5 29.61
Create a stacked plot and return a StackedLineChart
object.
s = stackedplot(outdoors)
s = StackedLineChart with properties: SourceTable: [51x3 timetable] DisplayVariables: {'Humidity' 'TemperatureF' 'PressureHg'} Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 EventsVisible: on Use GET to show all properties
The object provides access to many properties that apply to all the plots. For example, you can use s.LineWidth
to make the lines wider.
s.LineWidth = 2;
The object also provides access to arrays of objects that you can use to modify the lines and y-axes for individual plots. To access properties of individual lines, use s.LineProperties
. For each plot, you can specify a different line style, marker, plot type, and so on.
s.LineProperties
ans=3×1 StackedLineProperties array with properties:
Color
MarkerFaceColor
MarkerEdgeColor
LineStyle
LineWidth
Marker
MarkerSize
PlotType
Change the second plot to a scatter plot, and the third plot to a stair plot, using the PlotType
property.
s.LineProperties(2).PlotType = "scatter"; s.LineProperties(3).PlotType = "stairs";
You also can access individual y-axes through the s.AxesProperties
property.
s.AxesProperties
ans=3×1 StackedAxesProperties array with properties:
YLimits
YScale
LegendLabels
LegendLocation
LegendVisible
CollapseLegend
For example, change the y-limits of the first plot.
s.AxesProperties(1).YLimits = [46 54];
Plot And Change Multiple Lines in One Y-Axis
Create a table from a subset of patient data, using the Weight
, Systolic
, and Diastolic
variables.
load patients
tbl = table(Weight,Systolic,Diastolic);
head(tbl,3)
Weight Systolic Diastolic ______ ________ _________ 176 124 93 163 109 77 131 125 83
Create a stacked plot, with Systolic
and Diastolic
plotted using the same y-axis, and Weight
using its own y-axis. First, specify vars
as a cell array with two elements. The first element groups "Systolic"
and "Diastolic"
together in a string array. They are plotted together on a common y-axis. The second element of the cell array is "Weight"
. It is plotted on its own y-axis. Also, return a StackedLineChart
object that has the properties of the stacked plot.
vars = {["Systolic","Diastolic"],"Weight"}
vars=1×2 cell array
{["Systolic" "Diastolic"]} {["Weight"]}
s = stackedplot(tbl,vars)
s = StackedLineChart with properties: SourceTable: [100x3 table] DisplayVariables: {{1x2 cell} 'Weight'} XVariable: [] Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 Use GET to show all properties
When you plot multiple variables in one y-axis, you can assign different styles to the lines within that y-axis by assigning an array that specifies the styles.
For example, to specify the same color for both lines in the first y-axis, assign it to s.LineProperties(1).Color
. To specify different line styles for the two lines, assign a string array that specifies two different styles to s.LineProperties(1).LineStyle
.
s.LineProperties(1).Color = "magenta"; s.LineProperties(1).LineStyle = ["--",":"];
Change Color Order for Multiple Inputs
Load two timetables from the sample MAT-files, indoors
and outdoors
.
load indoors.mat load outdoors.mat
Create a stacked plot.
s = stackedplot(indoors,outdoors);
Change the color order used to indicate which variables come from which timetable. If you have a few timetables, it can be practical to choose colors by name.
colororder(s,["magenta","green"])
If you plot variables from a larger number of input tables or timetables, it might be more practical to set the color order by using a colormap. Specify that the colormap has n colors, where n is the number of tables or timetables you specified when you created the stacked plot.
For example, set the color order using the parula
function to return the parula colormap. Specify the number of colors as being equal to the number of timetables. If you do not know how many tables or timetables are shown in the stacked plot, use the SourceTable
property of the StackedLineChart
object returned by stackedplot
.
numTimetables = numel(s.SourceTable); colororder(s,parula(numTimetables))
Semilog Plot with Y-Axis Log Scale
Import data into a timetable. Then make a stacked plot. By default, all plots have linear scales on both their x- and y-axes.
tbl = readtimetable("outages.csv");
tbl = sortrows(tbl);
s = stackedplot(tbl)
s = StackedLineChart with properties: SourceTable: [1468x5 timetable] DisplayVariables: {'Loss' 'Customers' 'RestorationTime'} Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 EventsVisible: on Use GET to show all properties
You can access properties of individual y-axes, such as their scales, through the s.AxesProperties
property.
s.AxesProperties
ans=3×1 StackedAxesProperties array with properties:
YLimits
YScale
LegendLabels
LegendLocation
LegendVisible
CollapseLegend
To turn the first and second plots into semilog plots, with log scales on their y-axes, set their YScale
properties to 'log'
.
s.AxesProperties(1).YScale = 'log'; s.AxesProperties(2).YScale = 'log';
Input Arguments
tbl
— Input table or timetable
table | timetable
Input table or timetable. The stackedplot
function plots all
the numeric, logical, categorical
, datetime
, and
duration
variables, and ignores table variables of any other data
type. If tbl
has more than 25 variables,
stackedplot
plots the first 25.
To specify multiple input tables or timetables, use a comma-separated list or a cell
array of tables or timetables. When specifying multiple inputs, you cannot mix tables
and timetables in one call to stackedplot
.
vars
— Variables in input tables or timetables
string array | numeric array | logical array | cell array | vartype
subscript
Variables in the input tables or timetables, specified using one of the indexing schemes from the table.
Note: If you create a stacked plot from multiple
tables or timetables, then vars
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:
|
|
Variable index (for single table or timetable only):
|
|
Variable type (for single table or timetable only):
|
|
Variables specified in nested cell array:
|
|
Example: stackedplot(tbl,[1 3 4])
specifies the first, third, and
fourth variables.
Example: stackedplot(tbl,{["Temp1","Temp2"],"Pressure"})
uses a
nested cell array to specify that Temp1
and Temp2
are plotted in the same y-axis.
Example: stackedplot(tbl,{{1,2},5})
specifies variables by number
and plots the first and second variables in the same
y-axis.
X
— x-values
numeric vector | datetime vector | duration vector | logical vector
x-values, specified as a numeric, datetime, duration, or
logical vector. The length of X
must equal the number of rows of
Y
.
Y
— y-values
numeric array | datetime array | duration array | categorical array | logical array
y-values, specified as a numeric, datetime, duration,
categorical, or logical array. The stackedplot
function plots each
column in a separate y-axis.
LineSpec
— Line style, marker, and color
string scalar | character vector
Line style, marker, and color, specified as a string scalar or character vector containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.
Example: "--or"
is a red dashed line with circle markers.
Line Style | Description | Resulting Line |
---|---|---|
"-" | Solid line |
|
"--" | Dashed line |
|
":" | Dotted line |
|
"-." | Dash-dotted line |
|
Marker | Description | Resulting Marker |
---|---|---|
"o" | Circle |
|
"+" | Plus sign |
|
"*" | Asterisk |
|
"." | Point |
|
"x" | Cross |
|
"_" | Horizontal line |
|
"|" | Vertical line |
|
"square" | Square |
|
"diamond" | Diamond |
|
"^" | Upward-pointing triangle |
|
"v" | Downward-pointing triangle |
|
">" | Right-pointing triangle |
|
"<" | Left-pointing triangle |
|
"pentagram" | Pentagram |
|
"hexagram" | Hexagram |
|
Color Name | Short Name | RGB Triplet | Appearance |
---|---|---|---|
"red" | "r" | [1 0 0] |
|
"green" | "g" | [0 1 0] |
|
"blue" | "b" | [0 0 1] |
|
"cyan"
| "c" | [0 1 1] |
|
"magenta" | "m" | [1 0 1] |
|
"yellow" | "y" | [1 1 0] |
|
"black" | "k" | [0 0 0] |
|
"white" | "w" | [1 1 1] |
|
xvar
— Table variables that contain x-values
string array | character vector | cell array of character vectors | integer array | logical array
Table variables that contain x-values, specified as a string array, character vector, cell array of character vectors, integer array, or logical array.
You can specify xvar
only when the input arguments
tbl
or tbl1,...,tblN
are tables, not timetables,
vectors, or matrices.
If the input is one table, then
xvar
specifies one variable in the table.If the inputs are multiple tables, then
xvar
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
, thenxvar
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
, then specifyxvar
as["X1","X2","X3"]
.
parent
— Parent container
Figure
object | Panel
object | Tab
object | TiledChartLayout
object | GridLayout
object
Parent container, specified as a Figure
, Panel
,
Tab
, TiledChartLayout
, or GridLayout
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: stackedplot(tbl,Marker="o",MarkerSize=10)
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: stackedplot(tbl,"Marker","o","MarkerSize",10)
The stacked chart line properties listed here are only a subset common to all stacked plots, whether the data source is a table or array. For a complete list, see StackedLineChart Properties.
Color
— Line color
[0 0.4470 0.7410]
(default) | RGB triplet | hexadecimal color code | "r"
| "g"
| "b"
| ...
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 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: "blue"
Example: [0 0 1]
Example: "#0000FF"
LineStyle
— Line style
"-"
(default) | "--"
| ":"
| "-."
| "none"
Line style, specified as one of the options listed in this table.
Line Style | Description | Resulting Line |
---|---|---|
"-" | Solid line |
|
"--" | Dashed line |
|
":" | Dotted line |
|
"-." | Dash-dotted line |
|
"none" | No line | No line |
LineWidth
— Line width
0.5
(default) | positive value
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.
Marker
— Marker symbol
"none"
(default) | "o"
| "+"
| "*"
| "."
| ...
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 |
|
"+" | Plus sign |
|
"*" | Asterisk |
|
"." | Point |
|
"x" | Cross |
|
"_" | Horizontal line |
|
"|" | Vertical line |
|
"square" | Square |
|
"diamond" | Diamond |
|
"^" | Upward-pointing triangle |
|
"v" | Downward-pointing triangle |
|
">" | Right-pointing triangle |
|
"<" | Left-pointing triangle |
|
"pentagram" | Pentagram |
|
"hexagram" | Hexagram |
|
"none" | No markers | Not applicable |
MarkerSize
— Marker size
6
(default) | positive value
Marker size, specified as a positive value in points, where 1 point = 1/72 of an inch.
More About
Standalone Visualization
A standalone visualization is a chart designed for a special purpose that
works independently from other charts. Unlike other charts such as plot
and surf
, a standalone visualization has a preconfigured axes object
built into it, and some customizations are not available. A standalone visualization also
has these characteristics:
It cannot be combined with other graphics elements, such as lines, patches, or surfaces. Thus, the
hold
command is not supported.The
gca
function can return the chart object as the current axes.You can pass the chart object to many MATLAB functions that accept an axes object as an input argument. For example, you can pass the chart object to the
title
function.
Tips
To interactively explore the data in your stacked plot, use these features.
Zoom — Use the scroll wheel to zoom.
Pan — Click and drag the stacked plot to pan across the x-values.
Data cursor — Hover over a location to display y-values for each plot.
Version History
Introduced in R2018bR2023b: Plot events associated with timetables
The stackedplot
function can plot events as lines or shaded regions
on stacked plots created from timetables. To plot events associated with a timetable, you
must attach an event table to it before you call stackedplot
. For more
information on event tables, see eventtable
.
To support events, stackedplot
has a new
EventsVisible
name-value argument:
If
EventsVisible
is"on"
, thenstackedplot
plots events as lines or shaded regions.If
EventsVisible
is"off"
, thenstackedplot
hides events.
R2022b: Plot variables from multiple tables and timetables in a stacked plot
You can now plot variables from multiple input tables or timetables. In previous releases, you can plot variables only from a single table or timetable.
Also, these name-value arguments are added in R2022b. The corresponding
StackedLineChart
properties are also added in R2022b.
CombineMatchingNames
LegendLabels
LegendVisible
LegendOrientation
R2022a: Plot a variable multiple times in a stacked plot
You can display the same table or timetable variable multiple times in a stacked plot. In previous releases, specifying a variable more than once results in an error.
For example, create a timetable from the outages.csv
file. Then plot
the RestorationTime
variable under each of the other variables you
specify.
tbl = readtimetable("outages.csv"); tbl = sortrows(tbl); stackedplot(tbl,["Loss","RestorationTime","Customers","RestorationTime"])
See Also
Functions
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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
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
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)