Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h...

36
dr.dcd.h CS 101 /SJC 5th Edition 1 Chapter 3 Two-Dimensional Plots

Transcript of Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h...

Page 1: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 1

Chapter 3 Two-Dimensional Plots

Page 2: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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

Page 3: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 3

Logarithmic Scales2

Page 4: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 4

Logarithmic Scales3

Page 5: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 6: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 6

Controlling Axis2

Page 7: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 7

Controlling Axis3

Page 8: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 8

Controlling Axis4

Page 9: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 9

Controlling Axis5

Page 10: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 10

Controlling Axis6

Page 11: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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

Page 12: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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

Page 13: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 14: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 15: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 16: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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)

Page 17: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 18: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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)

Page 19: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 19

Enhanced Lines2

Page 20: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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

Page 21: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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

Page 22: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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:

Page 23: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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

Page 24: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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]

Page 25: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 26: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 27: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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]

Page 28: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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]

Page 29: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 29

Example 3.3

Plot gain of a cardioid microphone 2g cos(q)

Page 30: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 31: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 32: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 32

Additional Plotting Functions3

Basically, stairs plots are the envelopes of the bar charts.

Page 33: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

dr.dcd.h CS 101 /SJC 5th Edition 33

Additional Plotting Functions4

Basically, stem plots can be considered as narrowed bar charts.

Page 34: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 35: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.

Page 36: Chapter 3 Two-Dimensional Plotshung/cs101/chap03.pdfChapter 3 Two-Dimensional Plots . ... dr.dcd.h CS 101 /SJC 5th Edition 5 Controlling Axis Command Descriptions axis Returns axis

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.