Presentation is loading. Please wait.

Presentation is loading. Please wait.

3D-Graphs A 3D surface is defined as: z = f(x, y)

Similar presentations


Presentation on theme: "3D-Graphs A 3D surface is defined as: z = f(x, y)"— Presentation transcript:

1 3D-Graphs A 3D surface is defined as: z = f(x, y)
We will create 3D surfaces using 2 functions: mesh(x, y, z); surf(x, y, z); mesh(X,Y,Z) draws a wireframe mesh with color determined by Z, so color is proportional to surface height. If X andY are vectors, length(X) = n and length(Y) = m, where [m,n] = size(Z)

2 Example colormap colormap([1 0 0]) is red colormap([0 1 0]) is green
[X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; figure mesh(Z) xlabel('x'); ylabel('y'); zlabel('z'); colormap colormap([1 0 0]) is red colormap([0 1 0]) is green colormap([0 0 1]) is blue

3 Adding Plots to an Existing Graph
For example, these statements first create a contour plot of the peaks function, then superimpose a pcolor (pseudocolor) plot of the same function: % Obtain data from evaluating peaks function [x,y,z] = peaks; % Create pseudocolor plot pcolor(x,y,z) % Remove edge lines a smooth colors shading interp % Hold the current graph hold on % Add the contour graph to the pcolor graph contour(x,y,z,20,'k') % Return to default hold off The hold on command combines the pcolor plot with the contour plot in one figure.

4 Clearing the Figure for a New Plot
When a figure already exists, most plotting commands clear the axes and use this figure to create the new plot. However, these commands do not reset figure properties, such as the background color or the colormap. If you have set any figure properties in the previous plot, you might want to use the clf command with the reset option, clf reset before creating your new plot to restore the figure’s properties to their defaults.

5 Dis playing Multiple Plots in One Figure
The subplot command enables you to display multiple plots in the same window or print them on the same piece of paper. Typing subplot(m,n,p) partitions the figure window into an m-by-n matrix of small subplots and selects the pth subplot for the current plot. The plots are numbered along the first row of the figure window, then the second row, and so on.

6 playing Multiple Plots in One Figure
For example, these statements plot data in four different subregions of the figure window: t = 0:pi/10:2*pi; [X,Y,Z] = cylinder(4*cos(t)); subplot(2,2,1); mesh(X) subplot(2,2,2); mesh(Y) subplot(2,2,3); mesh(Z) subplot(2,2,4); mesh(X,Y,Z) Controlling the Axes The axis command provides a number of options for setting the scaling, orientation, and aspect ratio of graphs

7 Automatic Axis Limits and Tick Marks
By default, MATLAB finds the maxima and minima of the data and chooses the axis limits to span this range. MATLAB selects the limits and axis tick mark values to produce a graph that clearly displays the data. However, you can set your own limits using the axis or xlim, ylim, and zlim functions.

8 Setting Axis Limits The axis command enables you to specify your own limits: axis([xmin xmax ymin ymax]) or for three-dimensional graphs, axis([xmin xmax ymin ymax zmin zmax]) Use the command axis auto to enable automatic limit selection again.

9 Setting Axis Visibility
You can use the axis command to make the axis visible or invisible. axis on makes the axes visible. This is the default. axis off makes the axes invisible Setting Grid Lines The grid command toggles grid lines on and off. The statement grid on turns the grid lines on, and grid off turns them back off again

10 Adding Axis Labels, Titles and Text
The xlabel, ylabel, and zlabel commands add x-, y-, and z-axis labels. The title command adds a title at the top of the figure and the text function inserts text anywhere in the figure. You can produce mathematical symbols using LaTeX notation in the text string, as the following example illustrates:

11 Adding Axis Labels and Titles
t = -pi:pi/100:pi; y = sin(t); plot(t,y) axis([-pi pi -1 1]) xlabel('-\pi \leq {\itt} \leq \pi') ylabel('sin(t)') title('Graph of the sine function') text(0.5,-1/3,'{\itNote the odd symmetry.}') The location of the text string is defined in axes units (that is, the same units as the data).


Download ppt "3D-Graphs A 3D surface is defined as: z = f(x, y)"

Similar presentations


Ads by Google