1 / 34

EGR 106 Lecture 6 2-D Plotting

Learn about the useful plotting options in MATLAB for analyzing, visualizing, and presenting technical information. This lecture covers line specifiers, properties, axis limits, grid lines, adding text, creating multiple plots, and other special cases.

wjacqueline
Download Presentation

EGR 106 Lecture 6 2-D Plotting

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. EGR 106 Lecture 62-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize, and present their work. • Matlab has many useful plotting options available! We’ll review some of them today. • Textbook 5.1, 5.3-5.12

  2. What Would You Rather See? -1.0000 -0.8610 -0.7953 -0.7557 -0.7328 -0.7227 -0.7238 -0.7354 -0.7571 -0.7893 -0.8321 -0.8862 -0.9520 -1.0304 -1.1221 -1.2278 -1.3485 -1.4851 -1.6385 -1.8098 -2.0000 or

  3. Example Problem: x = –3:0.1:3; y = x.^3 – 5*x.^2 + 4; plot(x,y) xlabel('value of x') ylabel('value of y') title('Problem 10') text(0,1, 'egr106 week 1') colon and dot notation for arrays standard form for plot annotation tools

  4. default is Figure 1, blue lines, and small text scales are automatic note axis labels & text

  5. Matlab has interactive tools for modifying plots within the Figure window

  6. Click on the arrow to start interaction Double click on some part of the figure to initiate choices

  7. Modify text: Or the lines themselves:

  8. So, the property editor is like a spreadsheet’s tools, but….. • is limited to a single figure • is tedious to repeat for other plots • Command line manipulation is available through optional additional arguments: plot(x,y, 'linespec' , 'Propname' , PropValue ) • line specifiers: color, line type, markers for data • property name and value: thickness, size, etc

  9. Line Specifiers plot(x,y, ' r : d ' ) red dotted line diamonds

  10. Color: k black r red b blue g green y yellow c cyan w white m magenta The order is not important ! General form: plot(x,y, '  ') Line type: • - solid • : dotted • -- dashed • -. dash-dot Symbol: • . point • o circle • x x-mark • s square • d diamond • etc.

  11. Line Properties and Values plot(x,y, 'linewidth',5 ) line width is 5 “points”

  12. Properties: linewidth markersize markeredgecolor markerfacecolor General form: plot(x,y,’  ’,value) Value: varies with each property • sizes in points • colors as strings Can have multiple pairs !

  13. Example: plot(x,y, '- k o' , 'LineWidth' , 3 , 'MarkerSize', 6,… 'MarkerEdgeColor','red','MarkerFaceColor','green')

  14. Multiple Plots on the Same Axes • Plot allows multiple sets of arrays and line specifiers: Note colors rotate

  15. Can also use hold to freeze the plot Now, note colors

  16. Two Useful Commands • figure • alone it opens a new window • figure(n) takes you to window n • ginput(1) • creates crosshairs on the screen • returns (x,y) location of cursor at mouse click • ginput(n) returns n pairs of locations

  17. Formatting Plots – Adding Text • xlabel( 'string' ) • ylabel( 'string' ) • title( 'string' ) • text( x, y, 'string' ) • gtext( 'string' ) – cursor controlled • legend( 'string1', … 'stringn', loc) Location where text is started

  18. Can add greek letters, sub and superscripts • E.g. gtext( '\beta_1 x^2' )

  19. Text properties allow manipulation of the look for example: gtext( 'cosine' , 'fontsize', 20, 'rotation', 45, 'color' , 'red', )

  20. Formatting Plots – The Axes • Adding a grid grid • Setting the axis limits: axis( [ xmin xmax ymin ymax ] )

  21. Example

  22. Can plot on logarithmic axes using: semilogx(x,y) semilogy(x,y) loglog(x,y) • Note – negative data is ignored

  23. Figure Files (not in the text) • Save to create a .fig file

  24. Print them: Copy for pasting Figures outside Matlab (not in the text)

  25. Multiple Axes in One Figure - Subplot subplot(2,2,1) plot(x1,y1) subplot(2,2,2) etc. Argument list is: rows, columns, choice

  26. Other Types of 2-D Plots - Polar x = 1:100; r = log10(x); t = x/10; polar( t, r ) magnitude angle in radians

  27. Vertical and horizontal bar plots, stem and stair plots, pie and compass plots:

  28. Histograms:

  29. Additional Notes • Line specifiers, properties, axis, grid, … work on many of the plot types • Most of these tools have additional features – use the help function • Three-dimensional plots are available (see chapter 10) with various viewpoint options. Will do these later in semester.

  30. Three-Dim. Examples

  31. Other Special Cases: • For array arguments: plot(x_array, y_array) • plots column by column • cycles through colors • For a single argument, plot(x): • plots imaginary versus real if x is complex • plots x versus index if x is real

  32. MATALB Allows High Level Interfaces – Graphical User Interfaces (GUI)

More Related