Lecture 13: Handle Graphics, 3D Plots
Lecture 13: Handle Graphics, 3D Plots
Table of Contents
Handle Graphics ................................................................................................................. 1
Graphics - IV: 3-D Plots ...................................................................................................... 5
plot3 ................................................................................................................................. 7
Mesh and Surface Plots ........................................................................................................ 9
Plots with Special Graphics ................................................................................................. 13
Polar coordinates grid in the xy plane ................................................................................... 18
View ............................................................................................................................... 19
Rotate View ..................................................................................................................... 21
Graphic Handles, 3D plots, Mesh and Surface Plots are discussed.
Handle Graphics
%For controlling the graphic appearance or for creating animations etc.
%Using Handle Graphics one can get handles of graphic objects and change
%the properties of the objects.
%get(handle) gets a list of all property names and their current values.
%get(handle,'PropertyName') gets the current value of the sought property.
%set(handle,'PropertyName','PropertyValue') Any property can be changed
%using this.
clf;
t = linspace(0,2*pi,100);
y = t.*sin(t);
hg1 = plot(t,y)
get(hg1)
hg1 =
175.01
DisplayName:
Annotation:
Color:
LineStyle:
LineWidth:
Marker:
MarkerSize:
MarkerEdgeColor:
MarkerFaceColor:
XData:
YData:
ZData:
''
[1x1 hg.Annotation]
[0 0 1]
'-'
0.5
'none'
6
'auto'
'none'
[1x100 double]
[1x100 double]
[1x0 double]
BeingDeleted: 'off'
ButtonDownFcn:
Children:
Clipping:
CreateFcn:
DeleteFcn:
BusyAction:
HandleVisibility:
HitTest:
Interruptible:
Selected:
SelectionHighlight:
Tag:
Type:
UIContextMenu:
UserData:
Visible:
Parent:
XDataMode:
XDataSource:
YDataSource:
ZDataSource:
[]
[0x1 double]
'on'
[]
[]
'queue'
'on'
'on'
'on'
'off'
'on'
''
'line'
[]
[]
'on'
174.01
'manual'
''
''
''
set(hg1,'color','r')
set(hg1,'linewidth',2,'linestyle','--')
set(hg1,'marker','o')
plotyy plot
x = 1:0.2:10;
y1 = exp(-x).*sin(x);
y2 = exp(x);
Dy = plotyy(x,y1,x,y2);
hy1 = get(Dy(1),'ylabel');
hy2 = get(Dy(2),'ylabel');
set(hy1,'string','e^-x sin(x)');
set(hy2,'string','e^x');
title('\bf Example of a Plotyy Plot');
imapprox
Lighting.
surfl
lighting
material
specular
diffuse
surfnorm
Color maps.
hsv
hot
gray
bone
copper
pink
white
flag
lines
colorcube
vga
jet
prism
cool
autumn
spring
winter
summer
Transparency.
alpha
- Transparency (alpha) mode.
alphamap
- Transparency (alpha) look-up table.
alim
- Transparency (alpha) scaling
Axis control.
axis
zoom
grid
box
hold
axes
subplot
daspect
pbaspect
xlim
ylim
zlim
-
Viewpoint control.
view
- 3-D graph viewpoint specification.
viewmtx
- View transformation matrix.
rotate3d
- Interactively rotate view of 3-D plot.
Camera control.
campos
- Camera
camtarget - Camera
camva
- Camera
camup
- Camera
camproj
- Camera
position.
target.
view angle.
up vector.
projection.
printing.
- Print graph or Simulink system; or save graph to MATLAB fi
- Printer defaults.
- Set paper orientation.
plot3
%syntax: plot3(x,y,z, 'style option', 'PropertyName','propertyvalue')
%plots in 3-D are annotated in the same way as in 2-D plots.
%eg. xlabel, ylabel, zlabel, title, text, grid, etc.
t = 0:0.1:10;
x = exp(-0.2*t).*cos(2*t);
y = exp(-0.2*t).*sin(2*t);
subplot(1,2,1)
plot(x,y);
title('\bf 2-D line plot');
xlabel('\bf x')
ylabel('\bf y')
grid on
subplot(1,2,2)
plot3(x,y,t);
title('\bf 3-D line plot');
xlabel('\bf x')
ylabel('\bf y')
zlabel('\bf t')
grid on
10
11
clear X Y Z
x = -3:0.25:3;
y = -3:0.25:3;
[X,Y] = meshgrid(x,y);
Z = 1.8.^(-1.5*sqrt(X.^2 + Y.^2).*cos(0.5*X).*sin(X));
%surface plot
figure(1)
surf(X,Y,Z); xlabel('x'); ylabel('y');zlabel('z');
%surface and contour plot (draws a contour plot beneath the surface)
figure(2)
surfc(X,Y,Z); xlabel('x'); ylabel('y');zlabel('z');
12
13
Plot a cylinder
%Syntax: [A,B,C] = cylinder(r); It returns A,B,C coordinates of cylinder
%with profile r ()
t = linspace(0,2*pi,20);
r = 1 + sin(t);
[X,Y,Z] = cylinder(r);
surf(X,Y,Z)
axis('square')
14
15
16
17
18
View
%Specifies viewing angle of observer; projects 3-D objects on 2-D planes.
%Useful for visualizing the perspectives of different geometrical shapes.
%syntax: view(azimuth,elevation)
%azimuth: Angle (in degrees) of rotation about the z-axis measured
%CCW from the negative y-axis. It is in xy-plane.
%elevation: vertical angle (in degrees) measured positive above the xy-plane.
%The default veiwing angles are az = -37.5 degree and el = 30 degree.
t = linspace(0,6*pi,100);
x = sqrt(t).*sin(2*t); y = sqrt(t).*cos(2*t); z = 0.5.*t;
subplot(2,2,1); plot3(x,y,z); grid on;
subplot(2,2,2); plot3(x,y,z); view(0,90);
19
View(2) %same as view(0,90), shows projection in the xz-plane View(3) %same as view(-37.5,30), shows
the default 3D view
%Draw a filled circle in 2D and view it in 3D
theta = linspace(0,2*pi,100);
x = cos(theta);
y = sin(theta);
subplot(1,2,1)
fill(x,y,'g'); axis('square');
subplot(1,2,2)
fill(x,y,'g'); axis('square');
view(3)
20
Rotate View
%Rotate in 3D button located in the toolbar of the figure window. Use mouse
%to rotate the view.
%There is a utility function called rotate3d. Turn it on and rotate the
%view using mouse
rotate3d on
21
22