| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
plot(Y)
plot(X1,Y1,...,Xn,Yn)
plot(X1,Y1,LineSpec,...,Xn,Yn,LineSpec)
plot(X1,Y1,LineSpec,'PropertyName',PropertyValue)
plot(axes_handle,X1,Y1,LineSpec,'PropertyName',PropertyValue)
h = plot(X1,Y1,LineSpec,'PropertyName',PropertyValue)
plot(Y) plots the columns of Y versus the index of each value when Y is a real number. For complex Y, plot(Y) is equivalent to plot(real(Y),imag(Y)).
plot(X1,Y1,...,Xn,Yn) plots each vector Yn versus vector Xn on the same axes. If one of Yn or Xn is a matrix and the other is a vector, plots the vector versus the matrix row or column with a matching dimension to the vector. If Xn is a scalar and Yn is a vector, plots discrete Yn points vertically at Xn. If Xn or Yn are complex, imaginary components are ignored. plot automatically chooses colors and line styles in the order specified by ColorOrder and LineStyleOrder properties of current axes.
plot(X1,Y1,LineSpec,...,Xn,Yn,LineSpec) plots lines defined by the Xn,Yn,LineSpec triplets, where LineSpec specifies the line type, marker symbol, and color. You can mix Xn,Yn,LineSpec triplets with Xn,Yn pairs: plot(X1,Y1,X2,Y2,LineSpec,X3,Y3).
plot(X1,Y1,LineSpec,'PropertyName',PropertyValue) manipulates plot characteristics by setting lineseries properties (of lineseries graphics objects created by plot). Enter properties as one or more name and value pairs.
plot(axes_handle,X1,Y1,LineSpec,'PropertyName',PropertyValue) plots using axes with the handle axes_handle instead of the current axes (gca).
h = plot(X1,Y1,LineSpec,'PropertyName',PropertyValue) returns a column vector of handles to lineseries objects (instead of lineseries objects), one handle per line.
Plot a sine curve:
x = -pi:.1:pi; y = sin(x); plot(x,y)

Create line plot using specific line width, marker color, and marker size:
x = -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x)); plot(x,y,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10)

Modify axis tick marks and tick labels:
x = -pi:.1:pi;
y = sin(x);
plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})

Add a plot title, axis labels, and annotations:
x = -pi:.1:pi;
y = sin(x);
p = plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
xlabel('-\pi \leq \Theta \leq \pi')
ylabel('sin(\Theta)')
title('Plot of sin(\Theta)')
% \Theta appears as a Greek symbol (see String)
% Annotate the point (-pi/4, sin(-pi/4))
text(-pi/4,sin(-pi/4),'\leftarrow sin(-\pi\div4)',...
'HorizontalAlignment','left')
% Change the line color to red and
% set the line width to 2 points
set(p,'Color','red','LineWidth',2)

Plot multiple line plots on the same axes:
plot(rand(12,1)) % hold axes and all lineseries properties, such as % ColorOrder and LineStyleOrder, for the next plot hold all plot(randn(12,1))
Set line color to be always black and line style order to cycle through solid, dash-dot, dash-dash, and dotted line styles:
set(0,'DefaultAxesColorOrder',[0 0 0],...
'DefaultAxesLineStyleOrder','-|-.|--|:')
plot(rand(12,1))
hold all
plot(rand(12,1))
hold all
plot(rand(12,1))
To plot variables in the MATLAB workspace:
In the MATLAB workspace browser, select one or more variables.
Choose the plot type from the
menu.
axes | axis | bar | gca | grid | hold | legend | line | lineseries properties | LineSpec | LineWidth | loglog | MarkerEdgeColor | MarkerFaceColor | MarkerSize | plot3 | plotyy | semilogx | semilogy | subplot | title | xlabel | xlim | ylabel | ylim
![]() | playshow | plot (timeseries) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |