Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

2-D line plot

`plot(X,Y)`

`plot(X,Y,LineSpec)`

`plot(X1,Y1,...,Xn,Yn)`

`plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn)`

`plot(Y)`

`plot(Y,LineSpec)`

`plot(___,Name,Value)`

`plot(ax,___)`

`h = plot(___)`

`plot(`

creates
a 2-D line plot of the data in `X`

,`Y`

)`Y`

versus the corresponding
values in `X`

.

If

`X`

and`Y`

are both vectors, then they must have equal length. The`plot`

function plots`Y`

versus`X`

.If

`X`

and`Y`

are both matrices, then they must have equal size. The`plot`

function plots columns of`Y`

versus columns of`X`

.If one of

`X`

or`Y`

is a vector and the other is a matrix, then the matrix must have dimensions such that one of its dimensions equals the vector length. If the number of matrix rows equals the vector length, then the`plot`

function plots each matrix column versus the vector. If the number of matrix columns equals the vector length, then the function plots each matrix row versus the vector. If the matrix is square, then the function plots each column versus the vector.If one of

`X`

or`Y`

is a scalar and the other is either a scalar or a vector, then the`plot`

function plots discrete points. However, to see the points you must specify a marker symbol, for example,`plot(X,Y,'o')`

.

`plot(`

creates a
2-D line plot of the data in `Y`

)`Y`

versus the index
of each value.

If

`Y`

is a vector, then the*x*-axis scale ranges from 1 to`length(Y)`

.If

`Y`

is a matrix, then the`plot`

function plots the columns of`Y`

versus their row number. The*x*-axis scale ranges from 1 to the number of rows in`Y`

.If

`Y`

is complex, then the`plot`

function plots the imaginary part of`Y`

versus the real part of`Y`

, such that`plot(Y)`

is equivalent to`plot(real(Y),imag(Y))`

.

`plot(___,`

specifies line
properties using one or more `Name,Value`

)`Name,Value`

pair arguments. For a
list of properties, see Line Properties. Use this option with any
of the input argument combinations in the previous syntaxes. Name-value pair
settings apply to all the lines plotted.

returns a column vector of
chart line objects. Use `h`

= plot(___)`h`

to modify properties of a specific
chart line after it is created. For a list of properties, see Line Properties.

Use

`NaN`

and`Inf`

values to create breaks in the lines. For example, this code plots the first two elements, skips the third element, and draws another line using the last two elements:plot([1,2,NaN,4,5])

`plot`

uses colors and line styles based on the`ColorOrder`

and`LineStyleOrder`

properties of the axes.`plot`

cycles through the colors with the first line style. Then, it cycles through the colors again with each additional line style.You can change the default colors and line styles by setting default values for the

`ColorOrder`

and`LineStyleOrder`

properties. For example, to set the default line styles to a solid line with asterisk markers, a dotted line, and circle markers with no line, use this command:set(groot,'defaultAxesLineStyleOrder',{'-*',':','o'})

For more information about setting defaults, see Default Property Values.