Main Content

stackedplot

Stacked plot of several variables with common x-axis

  • Stacked plot of several variables with common x-axis

Description

Table and Timetable Data

example

stackedplot(tbl) 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.

  • If tbl is a table, then stackedplot plots the variables against row numbers.

  • If tbl is a timetable, then stackedplot plots the variables against row times.

  • If tbl is a timetable with an attached event table, then stackedplot 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.

example

stackedplot(tbl1,...,tblN) plots the variables of multiple tables or timetables. The inputs must be either all tables or all timetables. (since R2022b)

stackedplot({tbl1,...,tblN}) specifies the input as a cell array whose elements are either all tables or all timetables. This syntax is equivalent to the previous syntax.

example

stackedplot(___,vars) plots only the table or timetable variables specified by vars.

Vector and Matrix Data

example

stackedplot(X,Y) plots the columns of Y versus the vector X up to a maximum of 25 columns.

stackedplot(Y) plots the columns of Y versus their row number. The x-axis scale ranges from 1 to the number of rows in Y.

Additional Options

stackedplot(___,LineSpec) sets the line style, marker symbol, and color. You can use this syntax with the input arguments of any of the previous syntaxes.

stackedplot(___,"XVariable",xvar) specifies table variables that provide the x-values for the stacked plot.

This syntax is supported only when the inputs are tables.

example

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.

example

stackedplot(___,Name,Value) 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.

stackedplot(parent,___) creates the stacked plot in the figure, panel, or tab specified by parent. The option parent can precede any of the input argument combinations in the previous syntaxes.

example

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

collapse all

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)

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

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 the Humidity variables from indoors and outdoors in the same y-axis.

stackedplot(indoors,outdoors)

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)

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

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 its DisplayVariables property:

s = stackedplot(tbl);
s.DisplayVariables = ["RestorationTime","Loss","Customers"]

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)

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)

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

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];

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 = ["--",":"];

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

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

collapse all

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.

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 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: 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-values, specified as a numeric, datetime, duration, or logical vector. The length of X must equal the number of rows of Y.

y-values, specified as a numeric, datetime, duration, categorical, or logical array. The stackedplot function plots each column in a separate y-axis.

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

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

Color NameShort NameRGB TripletAppearance
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

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, then xvar 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 specify xvar as ["X1","X2","X3"].

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.

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.

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.

More About

collapse all

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 R2018b

expand all