Professional Documents
Culture Documents
Chapter 5
A bargraph of vector x A bargraph of matrix y
8 8
6 6
4 4
2 2
0 0
1 2 3 4 5 1 2
Title
X axis label, complete with units
Y axis label, complete with units
hold on
Freezes the current plot, so that an additional plot
can be overlaid
When you use this approach the additional
line is drawn in blue – the default drawing
color
The first plot is drawn in blue
The hold on command
freezes the plot
The second
line is also
drawn in blue,
on top of the
original plot
To unfreeze the plot
use the hold off
command
You can also create multiple lines on a
single graph with one command
Matrix of Y
values
The peaks(100)
function creates
a 100x100 array
of values. Since
this is a plot of a
single variable,
we get 100
different line plots
5.1.2 Line, Color and Mark Style
For example
plot(x,y,':ok')
strings are identified with a tick mark
if you don’t specify style, a default is used
line style – none
mark style – none
color - blue
plot(x,y,':ok')
In this command
the : means use a dotted line
the o means use a circle to mark each point
the letter k indicates that the graph should be
drawn in black
(b indicates blue)
dotted line
circles
black
specify the
drawing
parameters for
each line after
the ordered pairs
that define the
line
Axis scaling
title(‘x^{2}’)
gives
x2
title(‘x_2’)
gives
x2
Section 5.2
Subplots
The subplot command allows you to
subdivide the graphing window into a grid of
m rows and n columns
subplot(m,n,p)
rows columns location
subplot(2,2,1)
2 columns
Peaks
0 1 2
-5
2
0 2
0
2 rows y
-2 -2
x
3 4
2 rows and 1
column
Section 5.3
Other Types of 2-D Plots
Polar Plots
Logarithmic Plots
Bar Graphs
Pie Charts
Histograms
X-Y graphs with 2 y axes
Function Plots
Polar Plots
Explore the
property editor to
see some of the
other ways you Change the
can adjust your Aspect Ratio
plot interactively Select Inspector
from the
Property Editor
If you adjust a figure interactively, you’ll lose
your improvements when you rerun your
program
5.6 Creating plots from the workspace
MATLAB will suggest plotting options and create
the plot for you
Saving your plots