Title: EGR 106 Lecture 11 Three Dimensional Plotting
1EGR 106 Lecture 11Three Dimensional Plotting
- 3-D Line Plots
- Mesh and Surface Plots
- Special Plots
- View Command
- Textbook 9.1 9.4
23-D Line Plots
- Recall 2-D plotting
- plot(x,y,line specifier,PropertyName,Propert
yValue) - Extend to 3-D
- plot3(x,y,z,line specifier,PropertyName,Prop
ertyValue)
3 3-D Line Plots - Example
- t00.16pi
- xsqrt(t).sin(2t)
- ysqrt(t).cos(2t)
- z0.5t
- plot3(x,y,z,'k','linewidth',1)
- grid on
- xlabel('x') ylabel('y') zlabel('z')
4Mesh and Surface Plots
- A function of two variables
- z f(x,y)
- can be represented graphically as a surface.
- First step
- Define a grid of x and y values
5Example -1? x ? 3, 1? y ? 4
6Matlab Command to Create Grid
- gtgt x -13
- gtgt y14
- gtgt X,Ymeshgrid(x,y)
- X
- -1 0 1 2 3
- -1 0 1 2 3
- -1 0 1 2 3
- -1 0 1 2 3
- Y
- 1 1 1 1 1
- 2 2 2 2 2
- 3 3 3 3 3
- 4 4 4 4 4
7Making Mesh and Surface Plots
- Example (Gilat text 2nd Editions Cover Figure)
8Mesh Plot
x-3.23 y-3.23 X,Ymeshgrid(x,y) Z1.8.
(-1.5sqrt(X.2Y.2)).cos(0.5Y).sin(X) mesh(X
,Y,Z) xlabel('x') ylabel('y')
zlabel('z') title('Mesh Plot')
9Mesh Plot mesh(X,Y,Z)
10 Surface Plot surf (X,Y,Z)
11Mesh and Contour Plot meshc(X,Y,Z)
12Surface and Contour Plot surfc(X,Y,Z)
13Surface Plot with Lighting surfl(X,Y,Z)
14Waterfall Plot waterfall(X,Y,Z)
152-D Contour Plot contour(X,Y,Z,25)
Number of contour lines
16 3-D Contour Plot contour3(X,Y,Z,25)
17 Filled Contour Plot contourf(X,Y,Z,25)
18 Special Plots
- Sphere
- Cylinder
- 3-D Bar Plot
- 3-D Pie Chart
19 Sphere Plot
X,Y,Zsphere(20) surf(X,Y,Z) xlabel('x')
ylabel('y') zlabel('z') axis square title('Plot
of a Sphere')
20 Cylinder Plot
tlinspace(0,pi,20) r1sin(t) X,Y,Zcylinder(
r) surf(X,Y,Z) axis square title('Plot of a
Cylinder')
21 3-D Bar Plot
Y1 6 7 2 6 7 3 5 7 4 5 7 3 4 7 2 3 6 1 2
7 bar3(Y) title('3D Bar Plot')
22 3-D Pie Plot
X5 9 14 20 explode0 0 1 0 pie3(X,explode)
23 The View Command
view(az,el) where az and el are angles given in
degrees
24 View Command Example
x-3.23 y-3.23 X,Ymeshgrid(x,y) Z1.8.
(-1.5sqrt(X.2Y.2)).cos(0.5Y).sin(X) surf(X
,Y,Z) xlabel('x') ylabel('y') zlabel('z')
25 View Command (cont.)
view(0,25)
view(30,25)
view(90,25)
view(60,25)
26 View Command (cont.)
view(0,0)
view(90,90)