Post on 28-May-2020
dr.dcd.h CS 101 /SJC 5th Edition 1
Chapter 3 Two-Dimensional Plots
dr.dcd.h CS 101 /SJC 5th Edition 2
Logarithmic Scales
Some time data in logarithmic scale can have linear property.
semilogy – uses a log10 scale on the y axis
semilogx – uses a log10 scale on the x axis
loglog – uses a log10 scale on both axes
dr.dcd.h CS 101 /SJC 5th Edition 3
Logarithmic Scales2
dr.dcd.h CS 101 /SJC 5th Edition 4
Logarithmic Scales3
dr.dcd.h CS 101 /SJC 5th Edition 5
Controlling Axis
Command Descriptions
axis Returns axis limits: [xmin, xmax, ymin, ymax].
axis(x) Sets axis limits to x, a 1x4 vector.
axis equal Sets the aspect ratio to be equal on both axes.
axis image Same as axis equal except that the axis box fits tightly around the data.
axis square Makes the current axis box square.
axis normal Cancels the effect of axis equal and axis square
axis auto Returns the axis scaling to its default.
axis on/off Turns on/off axis labeling, tick marks.
dr.dcd.h CS 101 /SJC 5th Edition 6
Controlling Axis2
dr.dcd.h CS 101 /SJC 5th Edition 7
Controlling Axis3
dr.dcd.h CS 101 /SJC 5th Edition 8
Controlling Axis4
dr.dcd.h CS 101 /SJC 5th Edition 9
Controlling Axis5
dr.dcd.h CS 101 /SJC 5th Edition 10
Controlling Axis6
dr.dcd.h CS 101 /SJC 5th Edition 11
Creating Multiple Plots by hold
Multiple plots on the same axes by use hold on/off to enable and disable overwriting
dr.dcd.h CS 101 /SJC 5th Edition 12
Creating Multiple Plots by figure
Creating multiple figure windows by using figure(figure_id) to create a new figure.
gcf returns the figure_id
dr.dcd.h CS 101 /SJC 5th Edition 13
Creating Multiple Plots by subplot
Multiple plots by using subplot(m,n,p) to divide the current figure into an m-by-n grid and creates a subplot in the position specified by p.
Frame id is assigned in a row-order.
dr.dcd.h CS 101 /SJC 5th Edition 14
Creating Multiple Plots by subplot2
Subplot frames can have different sizes as long as they are not overlaid.
dr.dcd.h CS 101 /SJC 5th Edition 15
Creating Multiple Plots by subplot3
Multiple plots by using subplot(row, col, n) to place at the nth sub-axes in a row-by-col grid.
dr.dcd.h CS 101 /SJC 5th Edition 16
Specially Spaced Data
Operators that produce equally-spaced samples:
first:incr:last
linspace(first,last,n)
Operator that produces logarithmic spacing samples:
logspace(first,last,n)
If n is not specified then 50 equally-spaced samples are producred. i.e.
logspace(first,last)=linspace(first,last,50)
dr.dcd.h CS 101 /SJC 5th Edition 17
Example 3.1
Show y=x2-10x+25 over the range [0,10] in different scales.
dr.dcd.h CS 101 /SJC 5th Edition 18
Enhanced Lines
Properties of a plotted line can be set by plot(x,y,’PropertyName’,value, …)
4 properties associated with plotted line
LineWidth
MarkerSize
MarkerFaceColor
MarkerEdgeColor
For example:
plot(x,y,’LineWidth’,3,’MarkerSize’,3)
dr.dcd.h CS 101 /SJC 5th Edition 19
Enhanced Lines2
dr.dcd.h CS 101 /SJC 5th Edition 20
Enhanced Text Strings
Use stream modifiers to enhance text strings (titles, labels, etc.) such as bold face, italics, and special symbols.
Common stream modifiers:
\bf, \it – bold face, italics
\rm – remove modifiers
\fontname{name} – specify font name
\fontsize{size} – specify font size
_{txt} – specify txt as a subscript
^{txt} - specify txt as a superscript
\color{color} – specify text color
dr.dcd.h CS 101 /SJC 5th Edition 21
Enhanced Text Strings2
Character Sequence
Greek Symbol
Character Sequence
Greek Symbol
Character Sequence
Mathmetic Symbol
\alpha a \int
\beta b \cong
\gamma g \Gamma G \sim
\delta d \Delta D \infty
\epsilon e \pm
\eta h \leq
\theta q \geq
\lambda l \Lambda L \neq
\mu m \propto
\nu n \div
\pi p \Pi P \circ
\phi f \leftrightarrow
\rho r \leftarrow
\sigma s \Sigma S \rightarrow
\tau t \uparrow
\omega w \Omega W \downarrow
dr.dcd.h CS 101 /SJC 5th Edition 22
Enhanced Text Strings3
For example: the following expression
'\fontsize{18}\color{blue}\int_{\Omega} \color{green}\int_{\Gamma}
\color{black}(\nu^{2}+3\nu\mu) \color{red}d\nud\mu'
Produces the following text:
dr.dcd.h CS 101 /SJC 5th Edition 23
Place Random Text
A text string can be randomly placed by:
text(x, y, string, <modifiers>)
Position modifiers are used to specify alignment:
HorizontalAligment: Left/Center/Right
VerticalAlignment: Top/Middle/Bottom
For example:
text(2,1.4,'\omega \color{red}abc\rm',… 'HorizontalAlignment', 'Center')
dr.dcd.h CS 101 /SJC 5th Edition 24
Example 3.2
Plot function y(t)=10 e-t/t sin(wt) over [0,10]
dr.dcd.h CS 101 /SJC 5th Edition 25
Homework Assignment #6
3.7 Exercises
Page 123: 3.1, 3.6, 3.11, 3.12
This assignment is due by next week.
Late submission will be penalized.
dr.dcd.h CS 101 /SJC 5th Edition 26
Polar Plots
Polar is a special plotting function, which plots data in polar coordinates.
The general form of polar function
polar(x, y)
Data in frequency domain using polar plots have a better illustration than by using linear plots.
dr.dcd.h CS 101 /SJC 5th Edition 27
Example 3.2 Refreshed
Plot function y(t)=10 e-t/t sin(wt) over [0,10]
dr.dcd.h CS 101 /SJC 5th Edition 28
Example 3.2 Refreshed2
Polar plot function y(t)=10 e-t/t sin(wt) over [0,10]
dr.dcd.h CS 101 /SJC 5th Edition 29
Example 3.3
Plot gain of a cardioid microphone 2g cos(q)
dr.dcd.h CS 101 /SJC 5th Edition 30
Additional Plotting Functions
Function Descriptions
bar Creates a vertical bar plot.
barh Creates a horizontal bar plot
stairs Creates a stair plot
stem Creates a vertical bar plot
compass Creates a polar plot with an arrow drawn from the origin to the location of each point
pie Creates a pie bar plot. This function determines the percentage of each item.
If pie(p, q) syntax is used, q is called an explode array which controls whether individual pie slices are separated from the rest of the pie.
dr.dcd.h CS 101 /SJC 5th Edition 31
Additional Plotting Functions2
To create multiple-bar chart, data needs to be arranged in column major order.
dr.dcd.h CS 101 /SJC 5th Edition 32
Additional Plotting Functions3
Basically, stairs plots are the envelopes of the bar charts.
dr.dcd.h CS 101 /SJC 5th Edition 33
Additional Plotting Functions4
Basically, stem plots can be considered as narrowed bar charts.
dr.dcd.h CS 101 /SJC 5th Edition 34
Additional Plotting Functions5
The points to compass plot are in Cartesian coord., not in polar form.
dr.dcd.h CS 101 /SJC 5th Edition 35
Additional Plotting Functions6
If pie(p, q) syntax is used, q is called an explode array which controls whether individual slices are separated from the pie.
dr.dcd.h CS 101 /SJC 5th Edition 36
Homework Assignment #7
Quiz 3.1
Page 114: 7
3.7 Exercises
Page 123: 3.5, 3.14
This assignment is due by next week.
Late submission will be penalized.