0% found this document useful (0 votes)
56 views

Lecture 13: Handle Graphics, 3D Plots

lpl

Uploaded by

Anshu Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Lecture 13: Handle Graphics, 3D Plots

lpl

Uploaded by

Anshu Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

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]

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

set(hg1,'marker','o')

%change the values of some y-coordinates by changing data points


yvec = get(hg1,'ydata');
yvec(15:20) = 0; yvec(40:45)=0;
set(hg1,'ydata',yvec);

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

Graphics - IV: 3-D Plots


%Extensive functions and tools for visualizing 3-D data.
%There are several 3-D analogs of special 2-D plotting functions.
%eg. plot3, stem3, bar3, pie3, contour3, etc.
help graph3d
Three dimensional graphs.
Elementary 3-D plots.
plot3
- Plot lines and points in 3-D space.
mesh
- 3-D mesh surface.
surf
- 3-D colored surface.
fill3
- Filled 3-D polygons.
Color control.
colormap
caxis
shading
hidden
brighten
colordef
graymon
cmpermute cmunique
-

Color look-up table.


Pseudocolor axis scaling.
Color shading mode.
Mesh hidden line removal mode.
Brighten or darken color map.
Set color defaults.
Set graphics defaults for gray-scale monitors.
Rearrange colors in colormap.
Eliminate unneeded colors in colormap of indexed image.

Lecture 13: Handle Graphics, 3D plots

imapprox

- Approximate indexed image by one with fewer colors.

Lighting.
surfl
lighting
material
specular
diffuse
surfnorm

3-D shaded surface with lighting.


Lighting mode.
Material reflectance mode.
Specular reflectance.
Diffuse reflectance.
Surface normals.

Color maps.
hsv
hot
gray
bone
copper
pink
white
flag
lines
colorcube
vga
jet
prism
cool
autumn
spring
winter
summer

Hue-saturation-value color map.


Black-red-yellow-white color map.
Linear gray-scale color map.
Gray-scale with tinge of blue color map.
Linear copper-tone color map.
Pastel shades of pink color map.
All white color map.
Alternating red, white, blue, and black color map.
Color map with the line colors.
Enhanced color-cube color map.
Windows colormap for 16 colors.
Variant of HSV.
Prism color map.
Shades of cyan and magenta color map.
Shades of red and yellow color map.
Shades of magenta and yellow color map.
Shades of blue and green color map.
Shades of green and yellow color map.

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
-

Control axis scaling and appearance.


Zoom in and out on a 2-D plot.
Grid lines.
Axis box.
Hold current graph.
Create axes in arbitrary positions.
Create axes in tiled positions.
Data aspect ratio.
Plot box aspect ratio.
X limits.
Y limits.
Z limits.

Viewpoint control.
view
- 3-D graph viewpoint specification.
viewmtx
- View transformation matrix.
rotate3d
- Interactively rotate view of 3-D plot.

Lecture 13: Handle Graphics, 3D plots

Camera control.
campos
- Camera
camtarget - Camera
camva
- Camera
camup
- Camera
camproj
- Camera

position.
target.
view angle.
up vector.
projection.

High level camera control.


camorbit
- Orbit camera.
campan
- Pan camera.
camdolly
- Dolly camera.
camzoom
- Zoom camera.
camroll
- Roll camera.
camlookat - Move camera and target to view specified objects.
cameratoolbar - Interactively manipulate camera.
High level light control.
camlight
- Creates or sets position of a light.
lightangle - Spherical position of a light.
Graph annotation.
title
- Graph title.
xlabel
- X-axis label.
ylabel
- Y-axis label.
zlabel
- Z-axis label.
text
- Text annotation.
gtext
- Mouse placement of text.
plotedit
- Experimental graph editing and annotation tools.
Hardcopy and
print
printopt
orient

printing.
- Print graph or Simulink system; or save graph to MATLAB fi
- Printer defaults.
- Set paper orientation.

See also GRAPH2D, SPECGRAPH.

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

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

Mesh and Surface Plots


%Surface, mesh and contour plots are convenient ways to represent data that
%is a function of two independent variables, i.e., z = f(x,y).
%To plot any functions of 2 indep. variables, one needs to create 3 arrays
%of equal size.
%Three steps are involved: first generate a grid of (x,y) coordinates, then
%evaluate the function at each grid point and finally create a 3D plot.
%creates an (X,Y) mesh grid
u = linspace(-3,3,50);
[X Y] = meshgrid(u,u);
%mesh plot
Z = X.*Y.*(X.^2 - Y.^2)./(X.^2 + Y.^2);
mesh(X,Y,Z)
%mesh and coontour plot (draws a contour plot beneath the mesh)
figure(2)
meshc(X,Y,Z); xlabel('x'); ylabel('y');zlabel('z');
%mesh curtain plot (draws a curtain around the mesh)
figure(3)

Lecture 13: Handle Graphics, 3D plots

meshz(X,Y,Z); xlabel('x'); ylabel('y');zlabel('z');

10

Lecture 13: Handle Graphics, 3D plots

11

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

Plots with Special Graphics


% * Plot a Sphere
%syntax: sphere; Returns x,y,z coordinates of a unit sphere with 20 faces
[X,Y,Z] = sphere(20);
surf(X,Y,Z)

13

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

3-d bar plot


%Syntax: bar3(Y); Each element in Y is one bar. Columns are grouped together.
Y = [1 6.5 7; 2 6 7; 3 5.5 7; 4 5 7; 3 4 7; 2 3 7; 1 2 7];
bar3(Y)

15

Lecture 13: Handle Graphics, 3D plots

3-D Pie Plot


%syntax: pie3(X,explode)
X = [5 9 14 20];
explode = [0 1 0 0];
pie3(X,explode)

16

Lecture 13: Handle Graphics, 3D plots

3-D Stem plot


%syntax: stem3(X,Y,Z)
t = 0:0.2:10;
x = t; y = sin(t); z = t.^1.5;
stem3(x,y,z,'fill')
grid on
xlabel('x'); ylabel('y'); zlabel('z');

17

Lecture 13: Handle Graphics, 3D plots

Polar coordinates grid in the xy plane


%A 3D plot of a function in which the value of z ( eg. z = r \theta) is
%given in polar coordinates.
%To convert polar to cartesian coordinates use pol2cart function.
[th, r] = meshgrid((0:5:360)*pi/180, 0:0.1:2);
Z = r.*th;
[X,Y] = pol2cart(th,r);
surf(X,Y,Z)
xlabel('x'); ylabel('y'); zlabel('z');

18

Lecture 13: Handle Graphics, 3D plots

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

%xy (top view)

subplot(2,2,3); plot3(x,y,z); view(0,0);

%xz (side view)

subplot(2,2,4); plot3(x,y,z); view(90,0); %yz (side view)


title('Illustration of 3-D plot, View')

19

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

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

Lecture 13: Handle Graphics, 3D plots

Published with MATLAB R2013b

22

You might also like