Uploaded by jasonesperadii

MATLAB-Cheat-Sheet-Plot-Formatting

advertisement
Plotting in MATLAB: Formatting Lines, Markers, and Legends
a MATLAB Cheat Sheet by SPARTAN PROFESSOR
LINE AND MARKER STYLE
Description:
plot(X,Y,LineSpec)creates the plot using the specified line style, marker, and color
specified as a character vector or string containing symbols.
Note 1:
The symbols can appear in any order, and you do not need to specify all three characteristics
(line style, marker, and color).
Note 2:
To specify the line style, marker, and color of multiple plots, use the syntax
plot(X1,Y1,LineSpec1,X2,Y2,LineSpec2,…,Xn,Yn,LineSpecn)
Example:
The syntax to specify a red dashed line with circular markers is plot(X,Y,'r--o')
b
g
r
c
m
y
k
w
Color
blue
green
red
cyan
magenta
yellow
black
white
.
o
x
+
*
s
d
_
|
v
^
<
>
p
h
Symbol
point
circle
cross
plus
asterisk
square
diamond
horizontal line
vertical line
triangle (down)
triangle (up)
triangle (left)
triangle (right)
pentagram (star)
hexagram
Line Type
solid
-dashed
-.
dash-dot
:
dotted
(none) no line
LEGEND LOCATION
Description:
legend(___,'Location',lcn) sets the location of the legend where the location is
specified as a character vector.
Example:
legend(___,'Location','northwest') positions the legend in the upper left.
lcn (Inside of Axes)
'north'
'south'
'east'
'west'
'northeast'
'northwest'
'southeast'
'southwest'
'best'
lcn (Outside of Axes)
'northoutside'
'southoutside'
'eastoutside'
'westoutside'
'northeastoutside'
'northwestoutside'
'southeastoutside'
'southwestoutside'
'bestoutside'
Description
top
bottom
right
left
top right
top left
bottom right
bottom left
least conflict
Spartan Professor LLC
spartanprofessor.com
LEGEND ORIENTATION
Description:
legend(___,'Orientation',ornt) sets the orientation of the legend where the orientation
is specified as a character vector. To stack the legends vertically specify 'vertical', to list
the legend items side-by-side specify 'horizontal'. The default orientation is vertical.
LEGEND BACKGROUND
Description:
legend(bkgd) adds or removes the background and outline of the legend box display. The
background is specified as a character vector. To remove the background and outline specify
'boxoff', to display the background and outline specify 'boxon'. The default is on.
EXAMPLE
–
–
–
–
–
–
–
–
–
–
–
–
–
-
theta = 35;
v1 = 10;
v2 = 12;
g = 9.81;
t = 0:0.1:1;
h1 = v1*sind(theta)*t - 1/2*g*t.^2;
h2 = v2*sind(theta)*t - 1/2*g*t.^2;
plot(t,h1,'r--o',t,h2,'k-s')
xlabel('Time (s)')
ylabel('Height (m)')
title('Projectile Height')
legend('v_1 = 10 m/s','v_2 = 12 m/s',...
'Location','southoutside','Orientation','horizontal')
legend('boxoff')
Projectile Height
2.5
2
1.5
Height (m)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
0.5
0
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Time (s)
v
1
= 10 m/s
v
2
Spartan Professor LLC
spartanprofessor.com
= 12 m/s
0.8
0.9
1
Download