ebook img

How to Use MATLAB for Graphics PDF

550 Pages·2016·7.18 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview How to Use MATLAB for Graphics

® MATLAB Graphics R2017a How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 ® MATLAB Graphics © COPYRIGHT 1984–2017 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc. Trademarks MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders. Patents MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information. Revision History ® March 2006 Online only New for MATLAB 7.2 (Release 2006a) ® September 2006 Online only Revised for MATLAB 7.3 (Release 2006b) ® March 2007 Online only Revised for MATLAB 7.4 (Release 2007a) ® September 2007 Online only Revised for MATLAB 7.5 (Release 2007b) ® March 2008 Online only Revised for MATLAB 7.6 (Release 2008a) This publication was previously part of the ® Using MATLAB Graphics User Guide. ® October 2008 Online only Revised for MATLAB 7.7 (Release 2008b) ® March 2009 Online only Revised for MATLAB 7.8 (Release 2009a) ® September 2009 Online only Revised for MATLAB 7.9 (Release 2009b) ® March 2010 Online only Revised for MATLAB 7.10 (Release 2010a) ® September 2010 Online only Revised for MATLAB 7.11 (Release 2010b) ® April 2011 Online only Revised for MATLAB 7.12 (Release 2011a) ® September 2011 Online only Revised for MATLAB 7.13 (Release 2011b) ® March 2012 Online only Revised for MATLAB 7.14 (Release 2012a) September 2012 Online only Revised for Version 8.0 (Release 2012b) March 2013 Online only Revised for Version 8.1 (Release 2013a) September 2013 Online only Revised for Version 8.2 (Release 2013b) March 2014 Online only Revised for Version 8.3 (Release 2014a) October 2014 Online only Revised for Version 8.4 (Release 2014b) March 2015 Online only Revised for Version 8.5 (Release 2015a) September 2015 Online only Revised for Version 8.6 (Release 2015b) March 2016 Online only Revised for Version 9.0 (Release 2016a) September 2016 Online only Revised for Version 9.1 (Release 2016b) March 2017 Online only Revised for Version 9.2 (Release 2017a) Contents Plots and Plotting Tools 1 Types of MATLAB Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Create Graph Using Plots Tab . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Customize Graph Using Plot Tools . . . . . . . . . . . . . . . . . . . . . 1-6 Open Plot Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Customize Objects in Graph . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Control Visibility of Objects in Graph . . . . . . . . . . . . . . . . . . 1-8 Add Annotations to Graph . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Close Plot Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Create Subplots Using Plot Tools . . . . . . . . . . . . . . . . . . . . . . 1-9 Create Simple Line Plot and Open Plot Tools . . . . . . . . . . . . 1-9 Create Upper and Lower Subplots . . . . . . . . . . . . . . . . . . . . 1-9 Add Data to Lower Subplot . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Add New Plot Without Overwriting Existing Plot . . . . . . . . 1-11 Basic Plotting Commands 2 Create 2-D Graph and Customize Lines . . . . . . . . . . . . . . . . . 2-2 Create 2-D Line Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Create Graph in New Figure Window . . . . . . . . . . . . . . . . . . 2-3 Plot Multiple Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Colors, Line Styles, and Markers . . . . . . . . . . . . . . . . . . . . . 2-5 Specify Line Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Specify Different Line Styles for Multiple Lines . . . . . . . . . . 2-7 Specify Line Style and Color . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Specify Line Style, Color, and Markers . . . . . . . . . . . . . . . . . 2-9 v Plot Only Data Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Add Title, Axis Labels, and Legend to Graph . . . . . . . . . . . . 2-13 Specify Axis Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 Change Axis Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 Use Semiautomatic Axis Limits . . . . . . . . . . . . . . . . . . . . . 2-20 Revert Back to Default Axis Limits . . . . . . . . . . . . . . . . . . . 2-21 Reverse Axis Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23 Display Axis Lines through Origin . . . . . . . . . . . . . . . . . . . 2-24 Specify Axis Tick Values and Labels . . . . . . . . . . . . . . . . . . . 2-28 Change Tick Value Locations and Labels . . . . . . . . . . . . . . 2-28 Rotate Tick Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30 Change Tick Label Formatting . . . . . . . . . . . . . . . . . . . . . . 2-32 Control Value in Exponent Label . . . . . . . . . . . . . . . . . . . . 2-33 Add Grid Lines and Edit Placement . . . . . . . . . . . . . . . . . . . 2-38 Display Grid Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38 Display Grid Lines in Specific Direction . . . . . . . . . . . . . . . 2-41 Edit Grid Line Placement . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43 Modify Visual Appearance of Grid Lines . . . . . . . . . . . . . . . 2-45 Combine Multiple Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48 Combine Plots in Same Axes . . . . . . . . . . . . . . . . . . . . . . . . 2-48 Create Multiple Axes in Figure Using Subplots . . . . . . . . . . 2-49 Add Super Title to Figure with Subplots . . . . . . . . . . . . . . . 2-51 Create Chart with Two y-Axes . . . . . . . . . . . . . . . . . . . . . . . . 2-55 Modify Properties of Charts with Two y-Axes . . . . . . . . . . . 2-64 Change Axes Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-64 Change Ruler Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-66 Specify Colors Using Default Color Order . . . . . . . . . . . . . . 2-68 Plot Imaginary and Complex Data . . . . . . . . . . . . . . . . . . . . 2-71 Create Heatmap from Tabular Data . . . . . . . . . . . . . . . . . . . 2-74 vi Contents Data Exploration Tools 3 Ways to Explore Graphical Data . . . . . . . . . . . . . . . . . . . . . . . 3-2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Types of Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Display Data Values Interactively . . . . . . . . . . . . . . . . . . . . . . 3-4 What Is a Data Cursor? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 Enabling Data Cursor Mode . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 Display Style — Datatip or Cursor Window . . . . . . . . . . . . 3-12 Selection Style — Select Data Points or Interpolate Points on Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13 Exporting Data Value to Workspace Variable . . . . . . . . . . . 3-13 Zooming in Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Zooming in 2-D and 3-D . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Zooming in 2-D Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Zooming in 3-D Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 Panning — Shifting Your View of the Graph . . . . . . . . . . . . 3-17 Rotate in 3-D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Enabling 3-D Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Selecting Predefined Views . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Rotation Style for Complex Graphs . . . . . . . . . . . . . . . . . . . 3-19 Undo/Redo — Eliminating Mistakes . . . . . . . . . . . . . . . . . . 3-21 Annotating Graphs 4 Exclude Objects from Graph Legend . . . . . . . . . . . . . . . . . . . 4-2 Specify Legend Descriptions During Line Creation . . . . . . . 4-5 Add Text to Specific Points on Graph . . . . . . . . . . . . . . . . . . 4-8 Add Text to Three Data Points on Graph . . . . . . . . . . . . . . . 4-8 Determine Minimum and Maximum Points and Add Text . . 4-11 vii Include Variable Values in Graph Text . . . . . . . . . . . . . . . . 4-15 Include Variable Value in Axis Label . . . . . . . . . . . . . . . . . 4-15 Include Loop Variable Value in Graph Title . . . . . . . . . . . . 4-16 Text with Mathematical Expression Using LaTeX . . . . . . . . 4-18 Add Text with Integral Expression to Graph . . . . . . . . . . . . 4-18 Add Text with Summation Symbol to Graph . . . . . . . . . . . . 4-20 Greek Letters and Special Characters in Graph Text . . . . . 4-23 Include Greek Letters in Graph Text . . . . . . . . . . . . . . . . . 4-23 Include Superscripts and Annotations in Graph Text . . . . . 4-24 TeX Markup Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26 Add Annotations to Graph Interactively . . . . . . . . . . . . . . . 4-30 Add Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30 Pin Annotations to Points in Graph . . . . . . . . . . . . . . . . . . 4-31 Add Text to Graph Interactively . . . . . . . . . . . . . . . . . . . . . . 4-33 Add Title and Axis Labels . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33 Add Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35 Add Annotations to Graph . . . . . . . . . . . . . . . . . . . . . . . . . 4-37 Align Objects in Graph Using Alignment Tools . . . . . . . . . . 4-39 Coloring Graphs 5 Creating Colorbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Change Color Scheme Using a Colormap . . . . . . . . . . . . . . . 5-10 How Surface Plot Data Relates to a Colormap . . . . . . . . . . 5-16 Relationship Between the Surface and the Colormap . . . . . . 5-16 Change the Direction or Pattern of Colors . . . . . . . . . . . . . . 5-17 How Image Data Relates to a Colormap . . . . . . . . . . . . . . . . 5-22 How Patch Data Relates to a Colormap . . . . . . . . . . . . . . . . 5-30 Relationship of the Colormap to x-, y-, and z-Coordinate Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-30 viii Contents Relationship of the Colormap to Face-Vertex Data . . . . . . . 5-34 Control Colormap Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-39 Differences Between Colormaps and Truecolor . . . . . . . . . 5-45 Differences in Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-45 Differences in Visual Presentation . . . . . . . . . . . . . . . . . . . 5-47 Creating Specialized Plots 6 Types of Bar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Modify Baseline of Bar Graph . . . . . . . . . . . . . . . . . . . . . . . . 6-10 Overlay Bar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 Combine Line and Bar Charts Using Two y-Axes . . . . . . . . 6-17 Color 3-D Bars by Height . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-21 Compare Data Sets Using Overlayed Area Graphs . . . . . . . 6-24 Offset Pie Slice with Greatest Contribution . . . . . . . . . . . . 6-29 Add Legend to Pie Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31 Label Pie Chart With Text and Percentages . . . . . . . . . . . . 6-34 Create Pie Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-34 Store Precalculated Percent Values . . . . . . . . . . . . . . . . . . . 6-35 Combine Percent Values and Additional Text . . . . . . . . . . . 6-36 Determine Horizontal Distance to Move Each Label . . . . . . 6-38 Position New Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39 Data Cursors with Histograms . . . . . . . . . . . . . . . . . . . . . . . 6-42 Color Analysis with Bivariate Histogram . . . . . . . . . . . . . . . 6-44 Control Categorical Histogram Display . . . . . . . . . . . . . . . . 6-50 ix Replace Discouraged Instances of hist and histc . . . . . . . . 6-58 Old Histogram Functions (hist, histc) . . . . . . . . . . . . . . . 6-58 Recommended Histogram Functions . . . . . . . . . . . . . . . . . . 6-58 Differences Requiring Code Updates . . . . . . . . . . . . . . . . . . 6-59 Combine Line and Stem Plots . . . . . . . . . . . . . . . . . . . . . . . . 6-67 Overlay Stairstep Plot and Line Plot . . . . . . . . . . . . . . . . . . 6-70 Combine Contour Plot and Quiver Plot . . . . . . . . . . . . . . . . 6-73 Projectile Path Over Time . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-75 Label Contour Plot Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-77 Change Fill Colors for Contour Plot . . . . . . . . . . . . . . . . . . . 6-79 Highlight Specific Contour Levels . . . . . . . . . . . . . . . . . . . . 6-81 Animation Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-84 Updating the Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-84 Optimizing Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-84 Trace Marker Along Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-86 Move Group of Objects Along Line . . . . . . . . . . . . . . . . . . . . 6-89 Animate Graphics Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-93 Line Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-97 Record Animation for Playback . . . . . . . . . . . . . . . . . . . . . . 6-100 Record and Play Back Movie . . . . . . . . . . . . . . . . . . . . . . . 6-100 Capture Entire Figure for Movie . . . . . . . . . . . . . . . . . . . . 6-101 Customize Polar Axes Grid Lines and Appearance . . . . . . 6-104 Compass Labels on Polar Axes . . . . . . . . . . . . . . . . . . . . . . 6-113 Create Line Plot with Markers . . . . . . . . . . . . . . . . . . . . . . 6-115 Add Markers to Line Plot . . . . . . . . . . . . . . . . . . . . . . . . . 6-115 Specify Marker Size and Color . . . . . . . . . . . . . . . . . . . . . 6-117 Control Placement of Markers Along Line . . . . . . . . . . . . . 6-119 x Contents

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.