EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show...
-
Upload
chester-fields -
Category
Documents
-
view
217 -
download
1
Transcript of EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show...
![Page 1: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/1.jpg)
EGR 106 Lecture 62-D Plotting
Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize, and present their work.
Matlab has many useful plotting options available!
We’ll review some of them today.
Textbook 5.1, 5.3-5.12
![Page 2: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/2.jpg)
What Would You Rather See?
-1.0000 -0.8610 -0.7953 -0.7557 -0.7328 -0.7227 -0.7238 -0.7354 -0.7571 -0.7893 -0.8321 -0.8862 -0.9520 -1.0304 -1.1221 -1.2278 -1.3485 -1.4851 -1.6385 -1.8098 -2.0000
or
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2
-1.8
-1.6
-1.4
-1.2
-1
-0.8
-0.6
x
y
![Page 3: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/3.jpg)
Example Problem:
x = –3:0.1:3;
y = x.^3 – 5*x.^2 + 4;
plot(x,y)
xlabel('value of x')
ylabel('value of y')
title('Problem 10')
text(0,1, 'egr106 week 1')
colon and dotnotation forarrays standard form
for plot
annotation tools
![Page 4: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/4.jpg)
scales areautomatic
default isFigure 1,blue lines,and smalltext
note axis labels & text
![Page 5: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/5.jpg)
Matlab has interactive tools for modifying plots within the Figure window
![Page 6: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/6.jpg)
Click on the arrow to start interaction
Double click on some part of the figure to initiate choices
![Page 7: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/7.jpg)
Modify text:
Or the lines themselves:
![Page 8: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/8.jpg)
So, the property editor is like a spreadsheet’s tools, but…..– is limited to a single figure– is tedious to repeat for other plots
Command line manipulation is available through optional additional arguments:
plot(x,y, 'linespec' , 'Propname' , PropValue )
– line specifiers: color, line type, markers for data– property name and value: thickness, size, etc
![Page 9: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/9.jpg)
Line Specifiers
plot(x,y, ' r : d ' )
red
dotted line
diamonds
![Page 10: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/10.jpg)
General form: plot(x,y, '  ')
Color:k black
r red
b blue
g green
y yellow
c cyan
w white
m magenta
Line type:- solid
: dotted
-- dashed
-. dash-dotSymbol:
. point
o circle
x x-mark
s square
d diamond
etc.
The order is not important !
![Page 11: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/11.jpg)
Line Properties and Values
plot(x,y, 'linewidth',5 )
line width is 5 “points”
![Page 12: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/12.jpg)
General form: plot(x,y,’  ’,value)
Properties:linewidth
markersize
markeredgecolor
markerfacecolor
Value: varies with each property
sizes in points
colors as strings
Can have multiple pairs !
![Page 13: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/13.jpg)
Example:
plot(x,y, '- k o' , 'LineWidth' , 3 , 'MarkerSize', 6,…
'MarkerEdgeColor','red','MarkerFaceColor','green')
![Page 14: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/14.jpg)
Multiple Plots on the Same Axes
Plot allows multiple sets of arrays and line specifiers:
Note colors rotate
![Page 15: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/15.jpg)
![Page 16: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/16.jpg)
Can also use hold to freeze the plot
Now, note colors
![Page 17: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/17.jpg)
Two Useful Commands
figure– alone it opens a new window – figure(n) takes you to window n
ginput(1) – creates crosshairs on the screen– returns (x,y) location of cursor at mouse click– ginput(n) returns n pairs of locations
![Page 18: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/18.jpg)
Formatting Plots – Adding Text
– xlabel( 'string' )– ylabel( 'string' )– title( 'string' )– text( x, y, 'string' )– gtext( 'string' ) – cursor controlled – legend( 'string1', … 'stringn', loc)
Location where text is started
![Page 19: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/19.jpg)
![Page 20: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/20.jpg)
Can add greek letters, sub and superscripts E.g. gtext( '\beta_1 x^2' )
![Page 21: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/21.jpg)
Text properties allow manipulation of the look for example:
gtext( 'cosine' , 'fontsize', 20, 'rotation', 45, 'color' , 'red', )
![Page 22: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/22.jpg)
Formatting Plots – The Axes
Adding a grid
gridSetting the axis limits:
axis( [ xmin xmax ymin ymax ] )
![Page 23: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/23.jpg)
Example
![Page 24: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/24.jpg)
Can plot on logarithmic axes using:
semilogx(x,y)
semilogy(x,y)
loglog(x,y)
Note – negative data is ignored
![Page 25: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/25.jpg)
Figure Files (not in the text)
Save to create a .fig file
![Page 26: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/26.jpg)
Figures outside Matlab (not in the text)
Print them: Copy for pasting
![Page 27: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/27.jpg)
Multiple Axes in One Figure - Subplot
subplot(2,2,1)
plot(x1,y1)
subplot(2,2,2)
etc.
Argument list is:rows, columns,
choice
![Page 28: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/28.jpg)
Other Types of 2-D Plots - Polar
x = 1:100;
r = log10(x);
t = x/10;
polar( t, r )
magnitude
angle in radians
0.5
1
1.5
2
30
210
60
240
90
270
120
300
150
330
180 0
![Page 29: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/29.jpg)
Vertical and horizontal bar plots, stem and stair plots, pie and compass plots:
-1.5 -1 -0.5 0 0.5 1 1.50
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10.3
0.4
0.5
0.6
0.7
0.8
0.9
1
14%
18%
23%
36%
9%
0.5
1
1.5
30
210
60
240
90
270
120
300
150
330
180 0
![Page 30: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/30.jpg)
Histograms:
![Page 31: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/31.jpg)
Additional Notes
Line specifiers, properties, axis, grid, … work on many of the plot types
Most of these tools have additional features – use the help function
Three-dimensional plots are available (see chapter 10) with various viewpoint options. Will do these later in semester.
![Page 32: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/32.jpg)
-1-0.5
00.5
1
-1
-0.5
0
0.5
10
10
20
30
40
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
0
20
40
-2-1
01
2
-2
-1
0
1
2-1
-0.5
0
0.5
1
Three-Dim. Examples
![Page 33: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/33.jpg)
For array arguments:plot(x_array, y_array)
– plots column by column– cycles through colors
For a single argument, plot(x):– plots imaginary versus real if x is complex– plots x versus index if x is real
Other Special Cases:
![Page 34: EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,](https://reader035.fdocuments.net/reader035/viewer/2022070413/5697bf991a28abf838c9169a/html5/thumbnails/34.jpg)
MATALB Allows High Level Interfaces –
Graphical User Interfaces (GUI)