plot option. 이쁘게 그려보자.

Posted 2012.12.19 01:24

plot

2-D line plot

Syntax

plot(Y)
plot(X1,Y1,...,Xn,Yn)
plot(X1,Y1,LineSpec,...,Xn,Yn,LineSpec)
plot(...,'PropertyName',PropertyValue,...)
plot(axes_handle,...)
h = plot(...)

Description

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, it 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, it plots discrete Yn points vertically at Xn. If Xnor Yn are complex, imaginary components are ignored. If Xn or Yn are matrices, they must be 2-D and the same size, and the columns of Yn are plotted against the columns of Xnplot 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, whereLineSpec specifies the line type, marker symbol, and color. You can mix Xn,Yn,LineSpec triplets withXn,Yn pairs: plot(X1,Y1,X2,Y2,LineSpec,X3,Y3).

plot(...,'PropertyName',PropertyValue,...) manipulates plot characteristics by setting lineseries properties (of lineseries graphics objects created by plot). Enter properties as one or more name-value pairs. Property name-value pairs apply to all the lines plotted. You cannot specify name-value pairs for each set of data.

plot(axes_handle,...) plots using axes with the handle axes_handle instead of the current axes (gca).

h = plot(...) returns a column vector of handles to lineseries objects, one handle per line.

Tips

Plot data can include NaN and inf values, which cause breaks in the lines drawn. For example,

plot([1:5,NaN,6:10])

Skips the sixth element and resumes line drawing at the seventh element with the Y value of 6.

Examples

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 and annotate the graph.

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'})
title('Sine Function');
xlabel('Radians');
ylabel('Function Value');

 

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(sin(x));
% hold axes and all lineseries properties, such as
% ColorOrder and LineStyleOrder, for the next plot
hold all
plot(sin(x+(pi/4)));

 

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(sin(x))
hold all
plot(cos(x))
hold all
plot(log(abs(x)))

« PREV : 1 : ··· : 39 : 40 : 41 : 42 : 43 : 44 : 45 : 46 : 47 : ··· : 68 : NEXT »