Anda di halaman 1dari 5

Line Plot / Line Graph [1]

Example: Cell Phone use in Anytowne, 1996-2002.

Source: www.statcan.ca/english/ (27 December 2006).

Line graphs are more popular than all other graphs combined because their visual characteristics
reveal data trends clearly and they are easy to create. Specifically, a line graph is a set of quantitative
(numeric) data, plotted in an x-y coordinate system, that are connected together by lines. The data used to create
a line graph must be composed of pairs of observations. For example, a time series is composed of pairs of
values: measurements or statistics of some type, and the time periods during which those measurements were
taken or for which those statistics were estimated.

 They are good at showing specific values of data, meaning that given one variable the other can
easily be determined.
 They show trends in data clearly, meaning that they visibly show how one variable is affected by the
other as it increases or decreases.
 They enable the viewer to make predictions about the results of data not yet recorded.

Unfortunately, it is possible to alter the way a line graph appears to make data look a certain way. This is done by
either not using consistent scales on the axes, meaning that the value in between each point along the axis may
not be the same, or, when comparing two graphs, using different scales for each. It is important to be aware of
how graphs can be made to look a certain way, even if that is not what the data are indicating. There will also be
data for which a scatterplot is a better solution. A scatterplot is more appropriate when there are multiple values
on the y-axis possible for a single value on the x-axis.

1. This definition is based on, and at some points quoted


from,www.mste.uiuc.edu/courses/ci330ms/youtsey/lineinfo.html andwww.statcan.ca/english

plot -2-D line plot


Syntax
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)
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 toplot(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 atXn. If Xn or Yn are complex, imaginary
components are ignored. plot automatically chooses colors and line styles in the order specified by ColorOrderand 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 lineseriesgraphics 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, one handle per line.
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:

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

Alternatives
To plot variables in the MATLAB workspace:

1. In the MATLAB workspace browser, select one or more variables.

2. Choose the plot type from the   menu.


See Also
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
How To
 Editing Plot Characteristics
 Creating Line Plots
 Annotating Graphs
 Creating Graphics from the Workspace Browser
 Axes Objects — Defining Coordinate Systems for Graphs
 

Anda mungkin juga menyukai