Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# stairs

Stairstep graph

## Description

example

stairs(Y) draws a stairstep graph of the elements in Y.

• If Y is a vector, then the x-axis scale ranges from 1 to length(Y).

• If Y is a matrix, then stairs draws one line per matrix column and the x-axis scale ranges from 1 to the number of rows in Y.

example

stairs(X,Y) plots the elements in Y at the locations specified in 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. Use this option with any of the input argument combinations in the previous syntaxes.

example

stairs(___,Name,Value) specifies stairseries properties using one or more Name,Value pair arguments.

example

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

example

h = stairs(___) returns a vector of stairseries object handles in h. When multiple stairseries are present, you can make changes to properties of a specific stairseries by specifying a particular handle.

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

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


### Set Marker Properties Using Stairseries Handle

Create a stairstep plot of two data series and return the two stairseries handles in array h.

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

figure
h = stairs(X,Y);


Set the markers of the first series to small circles and the second series to magenta filled circles by referring to the handles.

set(h(1),'Marker','o','MarkerSize',4)
set(h(2),'Marker','o','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

expand all

### Y — Elements to plotvector or matrix

Elements to plot, specified as a vector or matrix. When Y is a vector, stairs creates one stairseries. When Y is a matrix, stairs draws one line per matrix column and creates a separate stairseries for each column.

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

### X — Locations to plot elements in Yvector or matrix

Locations to plot elements in Y, 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'

Data Types: char

### axes_handle — Axes handlehandle

Axes handle, which is the reference to an axes object. Use the gca function to get the handle to the current axes, for example, axes_handle = gca;.

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

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

Line style, specified as the comma-separated pair consisting of 'LineStyle' and a line style specifier. This table lists supported line styles.

Specifier

Line Style

'- '

Solid line (default)

'--'

Dashed line

':'

Dotted line

'-. '

Dash-dot line

'none'

No line

Example: 'LineStyle','-.'

### 'LineWidth' — Line width0.5 (default) | scalar

Line width, specified as the comma-separated pair consisting of 'LineWidth' and a scalar in points.

Example: 'LineWidth',0.75

### 'Color' — Color[0 0 1] (blue) (default) | three-element RGB vector | string

Color, specified as the comma-separated pair consisting of 'Color' and a three-element RGB vector or a string containing the short or long name of the color. The RGB vector 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].

This table lists the predefined colors and their RGB equivalents.

RGB Vector

Short Name

Long Name

[1 1 0]

'y'

'yellow'

[1 0 1]

'm'

'magenta'

[0 1 1]

'c'

'cyan'

[1 0 0]

'r'

'red'

[0 1 0]

'g'

'green'

[0 0 1]

'b'

'blue'

[1 1 1]

'w'

'white'

[0 0 0]

'k'

'black'

Example: 'Color',[0 1 0]

Example: 'Color','green'

Example: 'Color','g'

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

Marker symbol, specified as the comma-separated pair consisting of 'Marker' and a marker specifier. This table lists supported marker symbols.

Specifier

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

Example: 'Marker','+'

Example: 'Marker','diamond'

### 'MarkerEdgeColor' — Marker edge color'auto' (default) | 'none' | three-element RGB vector | string

Marker edge color, specified as the comma-separated pair consisting of 'MarkerEdgeColor' and a color value. The color value can be one of the supported strings or an RGB vector, listed in the following tables.

Specifier

Result

'auto'

Uses same color as line color

'none'

Specifies no color, which makes unfilled markers invisible

For an RGB vector, use 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]. This table lists the predefined string colors and their RGB equivalents.

RGB Vector

Short Name

Long Name

[1 1 0]

'y'

'yellow'

[1 0 1]

'm'

'magenta'

[0 1 1]

'c'

'cyan'

[1 0 0]

'r'

'red'

[0 1 0]

'g'

'green'

[0 0 1]

'b'

'blue'

[1 1 1]

'w'

'white'

[0 0 0]

'k'

'black'

Example: 'MarkerEdgeColor',[1 .8 .1]

### 'MarkerFaceColor' — Marker face color'none' (default) | 'auto' | three-element RGB vector | string

Marker face color, specified as the comma-separated pair consisting of 'MarkerFaceColor' and a color value. MarkerFaceColor sets the fill color for markers that are closed shapes (circle, square, diamond, pentagram, hexagram, and the four triangles). The color value can be one of the supported strings or an RGB vector, listed in the following tables.

Specifier

Result

'auto'

Uses same color as marker edge color

'none'

Makes the interior of the marker transparent, allowing the background to show through (default)

For an RGB vector, use 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]. This table lists the predefined string colors and their RGB equivalents.

RGB Vector

Short Name

Long Name

[1 1 0]

'y'

'yellow'

[1 0 1]

'm'

'magenta'

[0 1 1]

'c'

'cyan'

[1 0 0]

'r'

'red'

[0 1 0]

'g'

'green'

[0 0 1]

'b'

'blue'

[1 1 1]

'w'

'white'

[0 0 0]

'k'

'black'

Example: 'MarkerFaceColor',[0 .8 1]

### 'MarkerSize' — Marker size6 (default) | scalar

Marker size, specified as the comma-separated pair consisting of 'MarkerSize' and a scalar in points.

Example: 'MarkerSize',7

## Output Arguments

expand all

### h — Stairseries object handlescalar or column vector

Stairseries object handle, specified as a scalar or column vector. This is a unique identifier, which you can use to query and modify the properties of a specific stairseries.

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