Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic.

Similar presentations


Presentation on theme: "Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic."— Presentation transcript:

1

2 Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic Plots Bar Graphs and Pie Charts Histograms X-Y Graphs with two Y-axes

3 Function Plots

4

5 Three Dimensional Line Plots The plot3 function is similar to the plot function, except that it accepts data in three dimensions Instead of just providing x and y vectors, the user must also provide a z vector These ordered triples are then plotted in three-space and connected with straight lines For example: clear, clc x = linspace(0,10*pi,1000); y = cos(x); z = sin(x); plot3(x,y,z) grid xlabel('angle'), ylabel('cos(x)') zlabel('sin(x)') title('A Spring') The title, labels, and grid are added to the graph in the usual way, with the addition of zlabel for the z -axis. The coordinate system used with plot3 is oriented using the right-handed coordinate system familiar to engineers

6

7

8 Surface Plots Surface plots allow to represent data as a surface Two types of surface plots Mesh plots Surf plots

9 Mesh Plots There are several ways to use mesh plots They can be used to good effect with a single two-dimensional mxn matrix In this application, the value in the matrix represents the z- value in the plot The x- and y- values are based on the matrix dimensions Take, for example, the following very simple matrix: z = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10; 2, 4, 6, 8, 10, 12, 14, 16, 18, 20; 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; The code mesh(z) xlabel('x-axis') ylabel('y-axis') zlabel('z-axis') generates the graph

10

11 Explanation of Graph The graph is a “mesh” created by connecting the points defined in z into a rectilinear grid Notice that the x -axis goes from 0 to 10 and y goes from 1 to 3 The matrix index numbers were used for the axis values

12 Mesh Plots Continued…. The mesh function can also be used with three arguments: mesh(x,y,z) In this case, x is a list of x -coordinates, y is a list of y -coordinates, and z is a list of z -coordinates. x = linspace(1,50,10) y = linspace(500,1000,3) z = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10; 2, 4, 6, 8, 10, 12, 14, 16, 18, 20; 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] The x vector must have the same number of elements as the number of columns in the z vector and the y vector must have the same number of elements as the number of rows in the z vector The command mesh(x,y,z) creates the plot Notice that the x -axis varies from 0 to 50, with data plotted from 1 to 50

13

14 Surf Plots Surf plots are similar to mesh plots, but surf creates a three- dimensional colored surface instead of a mesh The colors vary with the value of z The surf command takes the same input as mesh : either a single input— For example: surf(z), in which case it uses the row and column indices as x – and y -coordinates—or three matrices The command surf(x,y,z) using the same data as for mesh creates the graph

15

16 Continued…. The shading scheme for surface plots is controlled with the shading command The default (shown in previous slide) is “faceted.” Interpolated shading can create interesting effects The plot(in next slide) is created by adding shading interp to the previous list of commands

17

18 Continued…. Flat shading without the grid is generated when shading flat is used

19 Continued…. The color scheme used in surface plots can be controlled with the colormap function For example: colormap(gray) forces a grayscale representation for surface plots This may be appropriate if you’ll be making black-and-white copies of your plots Other available colormaps are autumn bone hot spring colorcube hsv summer cool pink winter copper prism jet (default) flag white

20 Example A more complicated surface can be created by calculating the values of Z : x= [-2:0.2:2]; y= [-2:0.2:2]; [X,Y] = meshgrid(x,y); Z = X.*exp(-X.^2 - Y.^2); In the preceding code, the meshgrid function is used to create the two-dimensional matrices X and Y from the one-dimensional vectors x and y The values in Z are then calculated The following code plots the calculated values: subplot(2,2,1) mesh(X,Y,Z) title('Mesh Plot'), xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis') subplot(2,2,2) surf(X,Y,Z) title('Surface Plot'), xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis') Either the x, y vectors or the X, Y matrices can be used to defi ne the x – and y - axes.

21

22 Contour Plots Contour plots are two-dimensional representations of three- dimensional surfaces, much like the familiar contour maps used by many hikers The contour command was used to create Figure c, and the surfc command was used to create Figure d(in next slide) : subplot(2,2,3) contour(X,Y,Z) xlabel('x-axis'), ylabel('y-axis'), title('Contour Plot') subplot(2,2,4) surfc(X,Y,Z) xlabel('x-axis'), ylabel('y-axis') title('Combination Surface and Contour Plot')

23

24 Pseudo Color Plots Pseudo color plots are similar to contour plots, except that instead of lines outlining a specific contour, a two-dimensional shaded map is generated over a grid MATLAB includes a sample function called peaks that generates the x, y, and z matrices of an interesting surface that looks like a mountain range: [x,y,z] = peaks; With the following code, we can use this surface to demonstrate the use of pseudo color plotssubplot(2,2,1) pcolor(x,y,z) The grid is deleted when interpolated shading is used: subplot(2,2,2) pcolor(x,y,z) shading interp

25 Continued…. You can add contours to the image by overlaying a contour plot: subplot(2,2,3) pcolor(x,y,z) shading interp hold on contour(x,y,z,20,'k') The number 20 specifies that 20 contour lines are drawn, and the 'k' indicates that the lines should be black If we hadn’t specified black lines, they would have been the same color as the pseudo color plot and would have disappeared into the image Finally, a simple contour plot was added to the figure for comparison: subplot(2,2,4) contour(x,y,z)

26

27 Editing Plots From The Menu Bar In addition to controlling the way plots look by using MATLAB commands, plots can be edited after thses have created The plot in next slide was created with the sphere command, which is one of several sample functions, like peaks, used to demonstrate plotting sphere

28 Continued…. In the figure, the Insert menu has been selected Notice that you can insert labels, titles, legends, text boxes, and so on, all by using this menu The Tools menu allows you to change the way the plot looks, by zooming in or out, changing the aspect ratio, etc. The figure toolbar, underneath the menu toolbar, offers icons that allow you to do the same thing

29 Continued…. The plot in the previous slide doesn’t really look like a sphere; it’s also missing labels and a title, and the meaning of the colors may not be clear This plot can be edited by first adjusting the shape: Select Edit -> Axes Properties from the menu toolbar From the Property Editor—>Axes window, select More Properties -> Data Aspect Ratio Mode Set the mode to manual

30

31 Continued…. Similarly, labels, a title, and a color bar were added (figure shown in next slide) using the Property Editor They could also have been added by using the Insert menu option on the menu bar Editing plot in this manner is more interactive and allows to fine-tune the plot’s appearance The only problem with editing a figure interactively is that if MATLAB program is run again, and all improvements will be lost

32

33 Creating Plots from Workspace Window A great feature of MATLAB is its ability to create plots interactively from the workspace window In this window, select a variable, then select the drop-down menu on the plotting icon (shown in Figure in next slide ) MATLAB will list the plotting options it “thinks” are reasonable for the data stored in variable Simply select the appropriate option, and your plot is created in the current figure window If you don’t like any of the suggested types of plot, choose More plots from the drop-down menu, and a new window will open with the complete list of available plotting options for you to choose from This is especially useful, because it may suggest options that had not occurred For example: (figure in next slide) scatter plot of the x and y matrices highlighted in the figure. The matrices were created by loading the seamount data set, which is built into MATLAB

34

35 Continued…. If you want to plot more than one variable, highlight the first, then hold down the Ctrl key and select the additional variables To annotate plots, use the interactive editing process The interactive environment is a rich resource The more information is get out by exploring and experimenting


Download ppt "Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic."

Similar presentations


Ads by Google