MATLAB Tips
  Comments or problems: Contact Dr. Timothy D. Placek
All Pages Copyright 2002 by Auburn University, Auburn, AL 36849

 

More about Plotting II


By default, MATLAB creates an "adequate" plot when you just use the plot routine. One feature of this approach is that MATLAB will control the appearance of the line and symbols used "automatically", that is, if you put three curve on one plot the color and line style are selected automatically. In order to control the ultimate appearance then you would need to edit the plot and reset the symbol, line type, color etc.

This can also be done at the time the plot is created using the following form of the plot procedure:

>>plot(x,y,s);

where "s" is a string of up to three characters controlling. The table below shows the possible values which can be employed and the example below shows how this can be employed in a MATLAB program.

Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from elements from any or all the following 3 columns:

color
symbol
line type
y
yellow
.
point
-
solid
m
magenta
o
circle
:
dotted
c
cyan
x
x-mark
-.
dashdot
r
red
+
plus
--
dashed
g
green
*
star  
b
blue
s
square
w
white
d
diamond
k
black
v
triangle (down)
 
^
triangle (up)
<
triangle (left)
>
triangle (right)
p
pentagram
h
hexagram

Therefore, to make a solid black line with "circles" you specify 'ko-'
and to make a blue dashed line with "plus signs" you specify 'b+--'
and to make a red solid line with "no symbol" you specify 'r-'

Here is an example plotting the sin(x) and cos(x) on the same graph.

>> x=0:0.05:2*pi;
>> plot(x,sin(x),'ko-',x,cos(x),'b+--');

Here is another example plotting the sin(x) and cos(x) on the same graph but storing the plot information as strings to allow it to be reused if desired.

>> s1='ko-';
>> s2='b+--';
>> plot(x,sin(x),s1,x,cos(x),s2);

More about plotting options will be discussed in the next "MATLAB Tip".

 

  

 

Comments or problems: Contact Dr. Timothy D. Placek
All Pages Copyright 2002 by Auburn University, Auburn, AL 36849
[AU Logo]