Lecture 06

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

University of Technology

Production Engineering and Metallurgy Department

3D Plots

Computer Programming II
2nd class
CAD/CAM
Lecture 06
Dr. Baraa Mohsen
 Matlab provides a wide range of 3D plot options.

2
Plot3
 Plots lines and points in space, just like plot but now for an
(x,y,z) pair
 Plot3(x,y,z), each a vector of equal length
 Use all the same specifiers to generate colors, line-types, etc.

3
Plot commands
 Note that almost all 2D plotting commands
such as xlabel, ylabel, title will still work in
3D plots
 3D plots can be added as subplots just like
any other plot type
 Some other special features and functions
exist…

4
Example:
x=linspace(0,2*pi,100);
y=sin(x);
z=x;
plot3(x,y,z,'LineWidth',2);
xlabel('xlabel here')
ylabel('ylabel here')
zlabel('zlabel here')
title('title here')

5
6
bar graph
Example:

y=[5 2 1; 8 7 3; 9 8 6; 5 5 5; 4 3 2] ;
bar (y)

or

y=[5 2 1;
8 7 3;
9 8 6;
5 5 5;
4 3 2] ;
bar (y)

7
8
Bar Graph 3D
Example:
y=[5 2 1;
8 7 3;
9 8 6;
5 5 5;
4 3 2] ;
bar3 (y)

xlabel('x axis')
ylabel('y axis')
zlabel('z axis')

9
10
area graph

Example:

y=[5 2 1;
8 7 3;
9 8 6;
5 5 5;
4 3 2];

area (y)

11
12
stairstep graph
Example:

x=linspace(0,2*pi,20);
subplot (2,1,1)
stairs(x, cos(x))
ylabel ('stairs')

subplot (2,1,2)
plot(x, cos(x))

13
14
Mesh
Connects a series of discrete data points with a mesh:
• mesh(x,y,z) where X(i) and Y(j) are the intersections of
the mesh and Z(i,j) is the height at that intersection.
• mesh(Z) assumes X and Y are simple 1..N and 1..M

15
Meshc,surfc
 Combination surface/mesh and contour plot
 Use like surf or mesh – meshc(x,y,z)

16
Example:
x=-10:10;
y = -10:10;
z= x.^2'*y.^2;
mesh(x,y,z)

17
Example:
x=-10:10;
y = -10:10;
z= x.^2'*y.^2;
surf (x,y,z)

18

You might also like