stairs

Stairstep graph

Syntax

• stairs(Y) example
• stairs(X,Y) example
• stairs(___,LineSpec) example
• stairs(___,Name,Value) example
• stairs(ax,___) example
• h = stairs(___) example
• [xb,yb] = stairs(___) example

Description

example

stairs(Y) draws a stairstep graph of the elements in Y. If Y is a vector, then stairs draws one line.If Y is a matrix, then stairs draws one line per matrix column.

example

stairs(X,Y) plots the elements in Y at the locations specified by X. The inputs X and Y must be vectors or matrices of the same size. Additionally, X can be a row or column vector and Y must be a matrix with length(X) rows. 

example

stairs(___,LineSpec) specifies a line style, marker symbol, and color. For example, ':*r' specifies a dotted red line with asterisk markers. Use this option with any of the input argument combinations in the previous syntaxes.

example

stairs(___,Name,Value) specifies stair properties using one or more Name,Value pair arguments. For example, 'Marker','o','MarkerSize',8 specifies 8 point circle markers.

example

stairs(ax,___) plots into the axes specified by ax instead of into the current axes (gca). The option, ax, can precede any of the input argument combinations in the previous syntaxes.

example

h = stairs(___) returns one or more stair objects. Use h to make changes to properties of a specific stair object after it is created. 

example

[xb,yb] = stairs(___) does not create a plot, but returns matrices xb and yb of the same size, such that plot(xb,yb) plots the stairstep graph.

Examples

collapse all

Plot Single Data Series

Create a stairstep plot of sine evaluated at 40 equally spaced values between 0 and .

X = linspace(0,4*pi,40); Y = sin(X); figure stairs(Y) 

The length of Y automatically determines and generates the x-axis scale.

Plot Multiple Data Series

Create a stairstep plot of two cosine functions evaluated at 50 equally spaced values between 0 and .

X = linspace(0,4*pi,50)'; Y = [0.5*cos(X), 2*cos(X)]; figure stairs(Y) 

The number of rows in Y automatically determines and generates the x-axis scale.

Plot Single Data Series at Specified x-Values

Create a stairstep plot of a sine wave evaluated at equally spaced values between 0 and . Specify the set of x-values for the plot.

X = linspace(0,4*pi,40); Y = sin(X); figure stairs(X,Y) 

The entries in Y are plotted against the corresponding entries in X.

Plot Multiple Data Series at Specified x-Values

Create a stairstep plot of two cosine waves evaluated at equally spaced values between 0 and . Specify the set of x-values for the plot.

X = linspace(0,4*pi,50)'; Y = [0.5*cos(X), 2*cos(X)]; figure stairs(X,Y) 

The first vector input, X, determines the x-axis positions for both data series.

Plot Multiple Data Series at Unique Sets of x-Values

Create a stairstep plot of two sine waves evaluated at different values. Specify a unique set of x-values for plotting each data series.

x1 = linspace(0,2*pi)'; x2 = linspace(0,pi)'; X = [x1,x2]; Y = [sin(5*x1),exp(x2).*sin(5*x2)]; figure stairs(X,Y) 

Each column of X is plotted against the corresponding column of Y.

Specify Line Style, Marker Symbol and Color

Create a stairstep plot and set the line style to a dot-dashed line, the marker symbol to circles, and the color to red.

X = linspace(0,4*pi,20); Y = sin(X); figure stairs(Y, '-.or') 

Create a stairstep plot and set the line width to 2, the marker symbols to diamonds, and the marker face color to cyan using Name,Value pair arguments.

X = linspace(0,4*pi,20); Y = sin(X); figure stairs(Y,'LineWidth',2,'Marker','d','MarkerFaceColor','c') 

Specify Axes for Stairstep Plots

Create a figure with two subplots and return the two axes handles, s(1) and s(2). Create a stairstep plot in each subplot by referring to the axes handles.

figure s(1) = subplot(2,1,1); s(2) = subplot(2,1,2); X = linspace(0,2*pi); Y1 = 5*sin(X); Y2 = sin(5*X); stairs(s(1),X,Y1) stairs(s(2),X,Y2) 

Modify Stairstep Plot After Creation

Create a stairstep plot of two data series and return the two stair objects.

X = linspace(0,1,30)'; Y = [cos(10*X), exp(X).*sin(10*X)]; h = stairs(X,Y); 

Use small circle markers for the first data series. Use magenta filled circles for the second series. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

h(1).Marker = 'o'; h(1).MarkerSize = 4; h(2).Marker = 'o'; h(2).MarkerFaceColor = 'm'; 

Create a Stairstep Plot using plot Function

Evaluate two cosine functions at 50 equally spaced values between 0 and and create a stairstep plot using plot.

X = linspace(0,4*pi,50)'; Y = [0.5*cos(X), 2*cos(X)]; [xb,yb] = stairs(X,Y); 

stairs returns two matrices of the same size, xb and yb, but no plot.

Use plot to create the stairstep plot with xb and yb.

figure plot(xb,yb) 

Input Arguments

collapse all

Y — y valuesvector or matrix

y values, specified as a vector or matrix. When Y is a vector, stairs creates one stair object. When Y is a matrix, stairs draws one line per matrix column and creates a separate stair object for each column.

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

X — x valuesvector or matrix

x values, specified as a vector or matrix. When Y is a vector, X must be a vector of the same size. When Y is a matrix, X must be a matrix of the same size, or a vector whose length equals the number of rows in Y.

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

LineSpec — Line style, marker symbol, and colorstring

Line style, marker symbol, and color, specified as a string. For more information on line style, marker symbol, and color options see LineSpec.

Example: ':*r'

ax — Axes objectaxes object

Axes object. If you do not specify an axes, then stairs plots into the current axes.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Marker','s','MarkerFaceColor','red' plots the stairstep graph with red square markers.

The properties listed here are only a subset. For a complete list, see Stair Properties.

'LineStyle' — Line style'-' (default) | '--' | ':' | '-.' | 'none'

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

StringLine StyleResulting Line
'-'Solid line

'--'Dashed line

':'Dotted line

'-.'Dash-dotted line

'none'No lineNo line

'LineWidth' — Line width0.5 (default) | positive value

Line width, specified as a positive value in point units. If the line has markers, then the line width also affects the marker edges.

Example: 0.75

'Color' — Line color[0 0.4470 0.7410] (default) | RGB triplet | color string | 'none'

Line color, specified as an RGB triplet, a color string, or 'none'. If you specify the Color as 'none', then the line is invisible.

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]. This table lists RGB triplet values that have equivalent color strings.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black'k'[0 0 0]

Example: 'blue'

Example: [0 0 1]

'Marker' — Marker symbol'none' (default) | marker string

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

StringMarker Symbol
'o'Circle
'+'Plus sign
'*'Asterisk
'.'Point
'x'Cross
'square' or 's'Square
'diamond' or 'd'Diamond
'^'Upward-pointing triangle
'v'Downward-pointing triangle
'>'Right-pointing triangle
'<'Left-pointing triangle
'pentagram' or 'p'Five-pointed star (pentagram)
'hexagram' or 'h'Six-pointed star (hexagram)
'none'No markers

Example: '+'

Example: 'diamond'

'MarkerSize' — Marker size6 (default) | positive value

Marker size, specified as a positive value in point units.

Example: 10

'MarkerEdgeColor' — Marker outline color'auto' (default) | 'none' | RGB triplet | color string

Marker outline color, specified as one of these values:

• 'auto' — Use the same color as the Color property.

• 'none' — Use no color, which makes unfilled markers invisible.

• RGB triplet or color string — Use the specified color.

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]. This table lists RGB triplet values that have equivalent color strings.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black'k'[0 0 0]

Example: [0.5 0.5 0.5]

Example: 'blue'

'MarkerFaceColor' — Marker fill color'none' (default) | 'auto' | RGB triplet | color string

Marker fill color, specified as one of these values:

• 'none' — Use no color, which makes the interior invisible.

• 'auto' — Use the same color as the Color property for the axes.

• RGB triplet or color string — Use the specified color.

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]. This table lists RGB triplet values that have equivalent color strings.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black'k'[0 0 0]

Example: [0.3 0.2 0.1]

Example: 'green'

Output Arguments

collapse all

h — Stair objectsscalar or column vector

Stair objects, returned as a scalar or a column vector. These are unique identifiers, which you can use to query and modify the properties of a specific stair object after it is created.

xb — x values for use with plotvector or matrix

x values for use with plot, specified as a vector or matrix. xb contains the appropriate values such that plot(xb,yb) creates the stairstep graph.

yb — y values for use with plotvector or matrix

y values for use with plot, specified as a vector or matrix. yb contains the appropriate values such that plot(xb,yb) creates the stairstep graph.