MATLAB The Language of Technical Computing Computation Visualization Programming Using MATLAB Graphics The MathWorks Version 6
Computation Visualization Programming Using MATLAB Graphics Version 6 MATLABÆ The Language of Technical Computing
Contents ap h cs Overview of MATLAB Graphics Plotting Your Data ofa plot Editing Plots Interactive Plot editing Using Functions to Edit graphs 14 Using Plot Edit Mode Starting Plot Edit Mode 1-6 Exiting Plot Edit Mode l-6 cting Objects in a graph 1-6 Cutting, Copying, and Pasting Objects Moving and Resizing Objects diting objects in a graph Saving Your Work 1-9 Saving a graph in Mat-File Format Printing figures 1-10 Getting Help 1-12 Changing Your View 1-13 ooming In and Out Rotating 3-D Axes 1-14 Using the Property Editor Starting the Property Editor
i Contents Graphics 1 Overview of MATLAB Graphics Plotting Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Anatomy of a Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Editing Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Interactive Plot Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Using Functions to Edit Graphs . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Using Plot Edit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Starting Plot Edit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Exiting Plot Edit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Selecting Objects in a Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Cutting, Copying, and Pasting Objects . . . . . . . . . . . . . . . . . . . 1-7 Moving and Resizing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Editing Objects in a Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Saving Your Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Saving a Graph in MAT-File Format . . . . . . . . . . . . . . . . . . . . . 1-9 Saving to a Different Format (Exporting Figures) . . . . . . . . . 1-10 Printing Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12 Changing Your View of an Axes . . . . . . . . . . . . . . . . . . . . . . . 1-13 Zooming In and Out on an Axes . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Rotating 3-D Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 Using the Property Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 Starting the Property Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Closing the Property Editor Editing Object Properties 1-17 Navigating Among Objects in a graph l-18 Identifying Objects in a graph Applying Your Changes 1-21 Using the Data Statistics Tool 1-22 Adding Plots of Statistics to a graph 1-22 Saving Statistics to the Workspace 1-23 Basic Plotting 2 Basic Plotting Commands 2-2 Creating Line Plots 2-2 Specifying Line Style Specifying the Color and Size of Lines 2-6 Adding Plots to an Existing graph 27 Plotting Only the Data Points 2-8 Plotting Markers and Lines 2-9 Line Styles for Black and white Output 2-10 Setting Default Line Styles Line plots of matrix Data 2-13 Plotting Imaginary and Complex Data Plotting with Two Y-Axes 2-16 Combining Linear and Logarithmic Axes 2-16 Setting Axis Parameters Axis Limits and Ticks Example- Specifying Ticks and Tick Labels 2-22 Setting Aspect Ratio Figure Windows Displaying Multiple Plots per Figure
ii Contents Closing the Property Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17 Editing Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17 Navigating Among Objects in a Graph . . . . . . . . . . . . . . . . . . . 1-18 Identifying Objects in a Graph . . . . . . . . . . . . . . . . . . . . . . . . . 1-20 Applying Your Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21 Using the Data Statistics Tool . . . . . . . . . . . . . . . . . . . . . . . . 1-22 Adding Plots of Statistics to a Graph . . . . . . . . . . . . . . . . . . . . 1-22 Saving Statistics to the Workspace . . . . . . . . . . . . . . . . . . . . . . 1-23 2 Basic Plotting Basic Plotting Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Creating Line Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Specifying Line Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Specifying the Color and Size of Lines . . . . . . . . . . . . . . . . . . . . 2-6 Adding Plots to an Existing Graph . . . . . . . . . . . . . . . . . . . . . . . 2-7 Plotting Only the Data Points . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Plotting Markers and Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 Line Styles for Black and White Output . . . . . . . . . . . . . . . . . 2-10 Setting Default Line Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Line Plots of Matrix Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 Plotting Imaginary and Complex Data . . . . . . . . . . . . . . . . . 2-15 Plotting with Two Y-Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Combining Linear and Logarithmic Axes . . . . . . . . . . . . . . . . . 2-16 Setting Axis Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 Axis Limits and Ticks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 Example – Specifying Ticks and Tick Labels . . . . . . . . . . . . . . 2-22 Setting Aspect Ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23 Figure Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26 Displaying Multiple Plots per Figure . . . . . . . . . . . . . . . . . . . . 2-26
Specifying the Target Axes Default color Scheme 2-28 Formatting Graphs Overview 3-2 Adding Titles to Graphs Using the Title Option on the Insert Menu 33 Using the property Editor to Add a Title Using the title Function Adding Legends to Graphs 36 Using the Legend Option on the Insert Menu 7 Using the Legend Function Positioning the legend Editing the legend 39 Removing the legend 3-10 Adding Axis Labels to Graphs 3-11 Using the Label Options on the Insert Menu Using the Property Editor to Add Axis labels Using Axis-Label Commands 3-15 Adding Text Annotations to Grap 3-17 Creating Text Annotations in Plot Editing Mode 3-18 Creating Text Annotations with the text or gtext Command.3-18 Text Alignment Example- Aligning Text 3-23 Editing Text Annotations Mathematical Symbols, Greek Letters, and TeX Characters. 3-25 Using Character and Numeric Variables in Text Example- Multiline Text Adding Arrows and Lines to Graphs ..3-31
iii Specifying the Target Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28 Default Color Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28 3 Formatting Graphs Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Adding Titles to Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Using the Title Option on the Insert Menu . . . . . . . . . . . . . . . . 3-3 Using the Property Editor to Add a Title . . . . . . . . . . . . . . . . . . 3-4 Using the title Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 Adding Legends to Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Using the Legend Option on the Insert Menu . . . . . . . . . . . . . . 3-7 Using the Legend Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Positioning the Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 Editing the Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 Removing the Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10 Adding Axis Labels to Graphs . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 Using the Label Options on the Insert Menu . . . . . . . . . . . . . . 3-12 Using the Property Editor to Add Axis labels . . . . . . . . . . . . . 3-12 Using Axis-Label Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Adding Text Annotations to Graphs . . . . . . . . . . . . . . . . . . . . 3-17 Creating Text Annotations in Plot Editing Mode . . . . . . . . . . 3-18 Creating Text Annotations with the text or gtext Command . 3-18 Text Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 Example – Aligning Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 Editing Text Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24 Mathematical Symbols, Greek Letters, and TeX Characters . 3-25 Using Character and Numeric Variables in Text . . . . . . . . . . 3-27 Example - Multiline Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28 Drawing Text in a Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Adding Arrows and Lines to Graphs . . . . . . . . . . . . . . . . . . . 3-31
Creating Arrows and Lines in Plot Editing Mode Editing Arrows and Line Annotations Adding Plots of Basic Statistics to Graphs 3-33 Example- Plotting the Mean of a Data Set 3-34 Formatting Plots of Data Statistics 3-36 Statistics Plotted by the Data Statistics Tool 3-36 Viewing Statistics for Multiple Plots 3-37 Saving Statistics to the mATLAB Workspace Creating Specialized Plots Bar and Area graphs Types of Bar graphs 42 Stacked Bar graphs to Show Contributing Amount 45 Specifying X-Axis Data 4-7 Overlaying Plots on Bar graphs 4-9 Area graphs 4-11 Comparing Datasets with Area graphs 4-12 Pie Charts 4-14 Removing a Piece from a Pie Charts 416 Histograms 4-17 Histograms in Cartesian Coordinate Systems 4-17 Histograms in Polar Coordinates 419 Specifying Number 4-20 Discrete Data Graphs 4-22 4-22 Combining Stem Plots with Line Plots 4-25 Three-Dimensional stem plots 4-26 Stairstep Plots Direction and Velocity Vector Graphs ompass Plot ..4-3
iv Contents Creating Arrows and Lines in Plot Editing Mode . . . . . . . . . . 3-31 Editing Arrows and Line Annotations . . . . . . . . . . . . . . . . . . . 3-32 Adding Plots of Basic Statistics to Graphs . . . . . . . . . . . . . . 3-33 Example - Plotting the Mean of a Data Set . . . . . . . . . . . . . . . 3-34 Formatting Plots of Data Statistics . . . . . . . . . . . . . . . . . . . . . 3-36 Statistics Plotted by the Data Statistics Tool . . . . . . . . . . . . . . 3-36 Viewing Statistics for Multiple Plots . . . . . . . . . . . . . . . . . . . . 3-37 Saving Statistics to the MATLAB Workspace . . . . . . . . . . . . . 3-38 4 Creating Specialized Plots Bar and Area Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Types of Bar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Stacked Bar Graphs to Show Contributing Amounts . . . . . . . . 4-5 Specifying X-Axis Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 Overlaying Plots on Bar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . 4-9 Area Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 Comparing Datasets with Area Graphs . . . . . . . . . . . . . . . . . . 4-12 Pie Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 Removing a Piece from a Pie Charts . . . . . . . . . . . . . . . . . . . . . 4-16 Histograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17 Histograms in Cartesian Coordinate Systems . . . . . . . . . . . . . 4-17 Histograms in Polar Coordinates . . . . . . . . . . . . . . . . . . . . . . . 4-19 Specifying Number of Bins . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20 Discrete Data Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22 Two–Dimensional Stem Plots . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22 Combining Stem Plots with Line Plots . . . . . . . . . . . . . . . . . . . 4-25 Three-Dimensional Stem Plots . . . . . . . . . . . . . . . . . . . . . . . . . 4-26 Stairstep Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29 Direction and Velocity Vector Graphs . . . . . . . . . . . . . . . . . . 4-31 Compass Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-31