1 / 68

CITS2401 Computer Analysis & Visualisation

Faculty of engineering, computing and mathematics. CITS2401 Computer Analysis & Visualisation. School of Computer Science and Software Engineering. Topic 6 Visualisations in Matlab. Material from MATLAB for Engineers, Moore, Chapters 5,14 Additional material by Peter Kovesi and Wei Liu.

kalila
Télécharger la présentation

CITS2401 Computer Analysis & Visualisation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Faculty of engineering, computing and mathematics CITS2401 Computer Analysis & Visualisation School of Computer Science and Software Engineering Topic 6 Visualisations in Matlab Material from MATLAB for Engineers, Moore, Chapters 5,14 Additional material by Peter Kovesiand Wei Liu

  2. Two Dimensional Plots • The x-y plot is the most commonly used plot by engineers • The independent variable is usually called x • The dependent variable is usually called y

  3. Consider this x-y data Time is the independent variable and distance is the dependent variable

  4. In the default mode the figure window is free floating, and appears on top of the MATLAB desktop. It is often convenient to “dock” the figure, using the docking arrow

  5. Engineers always add … • Title: use command title(‘Your title here’) • X axis label, complete with units: xlabel(‘x-Label’) • Y axis label, complete with units: ylabel(‘y-Label’) • Often it is useful to add a grid: gridon These commands apply to the most recently plotted figure. You can use sprintf to use formatted output. E.g.: title(sprintf(’F(x) between %d and %d', x(1),x(20)))

  6. To add an apostrophe to a title (or other annotation) you must enter the single quote twice – otherwise MATLAB interprets the single apostrophe as the end of the string.

  7. Creating multiple plots • MATLAB overwrites the figure window every time you request a new plot • To open a new figure window use the figure function – for example figure(2) • hold on • Freezes the current plot, so that an additional plot can be overlaid • When you use this approach the additional line is drawn in blue – the default drawing color

  8. The first plot is drawn in blue To unfreeze the plot use the hold off command

  9. You can also create multiple lines on a single graph with one command Each set of ordered pairs will produce a new line

  10. The legend function • The legend function is used to provide legends for each data set that have been displayed simultaneously on one set of axes via the plot(X1, Y1, X2, Y2, X3, Y3, ...) function. • For example: >> legend('Label 1', 'Label 2', ..., 'Label N'); % Adds a legend for each data set in the plot. • Type help legend at the Matlab command prompt to learn more about the many options available with this function.

  11. Creating and switching between figure windows • The figure function is used to control different figure (or plot) windows. >> figure; % Creates a new figure window. % This becomes the "current" figure. >> figure(N); % Makes figure N the current figure window. % This function creates a new figure window % called N if N does not already exist. >> delete(N); % Deletes figure N.

  12. Variations • If you use the plot command with a single matrix, MATLAB plots the values versus the index number • Usually this type of data is plotted on a bar graph • When plotted on an x-y grid, it is often called a line graph

  13. If you want to create multiple plots, all with the same x value you can… • Use alternating sets of ordered pairs • plot(x, y1, x, y2, x, y3, x, y4) • Or group the y values into a matrix • z=[y1, y2, y3, y4] • plot(x,z)

  14. The peaks(100) function creates a 100x100 array of values. Since this is a plot of a single variable, we get 100 different line plots The peaks(100) function creates a 100x100 array of values, and will plot itself .

  15. Plots of Complex Arrays • If the input to the plot command is a single array of complex numbers, MATLAB plots the real component on the x-axis and the imaginary component on the y-axis

  16. Line, Color and Mark Style • You can change the appearance of your plots by selecting user defined • line styles • color • mark styles • Try using help plot for a list of available styles

  17. Available choices

  18. Specify your choices in a string • For example • plot(x,y,':ok') • strings are identified with a tick mark • if you don’t specify style, a default is used • line style – none • mark style – none • color - blue

  19. dotted line circles black

  20. Axis scaling • MATLAB automatically scales each plot to completely fill the graph • If you want to specify a different axis – use the axis command axis([xmin,xmax,ymin,ymax]) • Lets change the axes on the graph we just looked at

  21. Subplots • The subplot command allows you to subdivide the graphing window into a grid of m rows and n columns • subplot(m,n,p) rows columns location

  22. Other Types of 2-D Plots • Polar Plots • Logarithmic Plots • Bar Graphs • Pie Charts • Histograms • X-Y graphs with 2 y axes • Function Plots

  23. Polar Plots • Some functions are easier to specify using polar coordinates than by using rectangular coordinates • For example the equation of a circle is • y=sin(x) in polar coordinates

  24. Logarithmic Plots • A logarithmic scale (base 10) is convenient when • a variable ranges over many orders of magnitude, because the wide range of values can be graphed, without compressing the smaller values. • data varies exponentially. • plot – uses a linear scale on both axes • semilogy – uses a log10 scale on the y axis • semilogx – uses a log10 scale on the x axis • loglog – use a log10 scale on both axes

  25. plot – uses a linear scale on both axes • semilogy – uses a log10 scale on the y axis • semilogx – uses a log10 scale on the x axis • loglog – use a log10 scale on both axes

  26. x-y plot – linear on both axes semilogx – log scale on the x axis semilogy – log scale on the y axis loglog – log scale on both axes

  27. Bar Graphs and Pie Charts • MATLAB includes a whole family of bar graphs and pie charts • bar(x) – vertical bar graph • barh(x) – horizontal bar graph • bar3(x) – 3-D vertical bar graph • bar3h(x) – 3-D horizontal bar graph • pie(x) – pie chart • pie3(x) – 3-D pie chart

  28. Histograms • A histogram is a plot showing the distribution of a set of values

  29. X-Y Graphs with Two Y Axes • Sometimes it is useful to overlay two x-y plots onto the same figure. However, if the order of magnitude of the y values are quite different, it may be difficult to see how the data behave.

  30. plotyy: plots two functions with separate axis.

  31. 5.3 Function Plots • Function plots allow you to use a function as input to a plot command, instead of a set of ordered pairs of x-y values • fplot('sin(x)',[-2*pi,2*pi]) function input as a string range of the independent variable – in this case x

  32. Three Dimensional Plotting • Line plots • Surface plots • Contour plots • Cylinder plots

  33. Three Dimensional Line Plots • These plots require a set of order triples ( x-y-z values) as input

  34. Just for fun • try the comet3 function, which draws the graph in an animation sequence • comet3(x,y,z) • If your animation draws too slowly, add more data points • For 2-D line graphs use the comet function

  35. Surface Plots • Represent x-y-z data as a surface • mesh - meshplot • surf – surface plot

  36. Using mesh with 3 variables • If we know the values of x and y that correspond to our z values, we can plot against those values instead of the index numbers

  37. Shading • There are several shading options • shading interp • shading flat • faceted flat is the default • You can also adjust the color scheme with the color map function

  38. Shading flat Default shading(faceted) Shading interp

  39. Colormaps

  40. Contour Plots • Contour plots use the same input syntax as mesh and surf plots • They create graphs that look like the familiar contour maps used by hikers

  41. To demonstrate these functions we used a more interesting example • A more complicated surface can be created by calculating the values of z, instead of just defining them • We’ll need to use the meshgrid function to create 2-D input arrays – which will then be used to create a 2-D result • [X,Y] = meshgrid(x,y) will return 2 n x m matrices where x is an n-vector and y is an m-vector.

More Related