I Overview of MatlaB graphics Plotting Your data The process of constructing a basic graph to meet your presentation graphics requirements is outlined in the following table. The table shows seven typical steps and some example code for each If you are performing analysis only, you may want to view various graphs just to explore your data. In this case, steps 1 and 3 may be all you need. If you are creating presentation graphics, you may want to fine-tune your graph by positioning it on the page, setting line styles and colors, adding annotations and making other such improvements Typical Code Prepare your data X=0: y1 bessel(1, x) ess y3= bessel(3, x) f: plot region within the window subplot(2,2, 1) 3 Call elementary plotting h= plot(x, y1, x, y2, x, y3); function 4 Select line and marker set(h, 'Linewidth,2, 'LineStyle),[-i:;-'1) characteristics set(h,{" Color'},{'r';'g';"b"}) 5 Set axis limits, tick marks, and axis([0 12-0.5 11) grid lines rid on 6 Annotate the graph with axis xlabel('Time) labels, legend, and text ylabel('Amplitude') legend(h 'First,'Second',Third) title( Bessel Functions [y, ix]=min(y1); text(x(ix),y,'First Min \rightarrow lorizontalAlignment','right) 7 Export graph print -depsc -tiff -r200 myplot 1-2
1 Overview of MATLAB Graphics 1-2 Plotting Your Data The process of constructing a basic graph to meet your presentation graphics requirements is outlined in the following table. The table shows seven typical steps and some example code for each. If you are performing analysis only, you may want to view various graphs just to explore your data. In this case, steps 1 and 3 may be all you need. If you are creating presentation graphics, you may want to fine-tune your graph by positioning it on the page, setting line styles and colors, adding annotations, and making other such improvements. Step Typical Code 1 Prepare your data x = 0:0.2:12; y1 = bessel(1,x); y2 = bessel(2,x); y3 = bessel(3,x); 2 Select a window and position a plot region within the window figure(1) subplot(2,2,1) 3 Call elementary plotting function h = plot(x,y1,x,y2,x,y3); 4 Select line and marker characteristics set(h,'LineWidth',2,{'LineStyle'},{'--';':';'-.'}) set(h,{'Color'},{'r';'g';'b'}) 5 Set axis limits, tick marks, and grid lines axis([0 12 −0.5 1]) grid on 6 Annotate the graph with axis labels, legend, and text xlabel('Time') ylabel('Amplitude') legend(h,'First','Second','Third') title('Bessel Functions') [y,ix] = min(y1); text(x(ix),y,'First Min \rightarrow',... 'HorizontalAlignment','right') 7 Export graph print −depsc -tiff -r200 myplot
Anatomy of a Plot matlaB plotting functions direct their output to a window that is separate from the command window. In matlAb this window is referred to as a figure For example, the following illustrates the plot of the Bessel functions, described Plotting Your Data"on page 1-2, highlighting the basic components of the MATLAB figure -+Fi 网口区 Eile Edit yiew Insert Iools window Help Da母AAx/P Axes on which ATLAB plot By default, MATLAB uses line style and color to distinguish the data sets plotted in the graph. However, you can change the appearance of these graphic omponents or add annotations to the graph to help explain your data for presentation graphics. For information, see"Editing Plots"on page 1-4
Plotting Your Data 1-3 Anatomy of a Plot MATLAB® plotting functions direct their output to a window that is separate from the command window. In MATLAB this window is referred to as a figure. For example, the following illustrates the plot of the Bessel functions, described in “Plotting Your Data” on page 1-2, highlighting the basic components of the graph. By default, MATLAB uses line style and color to distinguish the data sets plotted in the graph. However, you can change the appearance of these graphic components or add annotations to the graph to help explain your data for presentation graphics. For information, see “Editing Plots” on page 1-4. MATLAB figure window Axes on which MATLAB plots data Line plots representing data
I Overview of MatlaB graphics Editing plots MATLAB formats a graph to provide readability, setting the scale of axes, including tick marks on the axes, and using color and line style to distinguish the plots in the graph. However, if you are creating presentation graphics, you may want to change this default formatting or add descriptive labels, titles legends and other annotations to help explain your data. MATLAB supports two ways to edit the plots you create: Using the mouse to select and edit objects interactively Using MATLAB functions at the command-line or in an M-file Plot Editing If you enable plot editing mode in the matLAB figure window, you can perform point-and-click editing of your graph In this mode you can change the format of objects in your graph by double-clicking on the object and changing the values ofits properties. In plot editing mode, you access the properties through the a graphical user interface called the property editor. For more information about interactive editing, see "Using Plot edit Mode"on page 1-5. For information about editing object properties in plot editing mode see"Using the Property Editor"on page 1-15 Using Functions to Edit Graphs If you prefer to work from the matlaB command line or if you are creating an M-file, you can use MATLAB commands to edit the graphs you create. Taking dvantage of the MatLAB Handle graphics system, you can use the set and get commands to change the properties of the objects in a grap Note Plot editing mode provides an alternative way to access the properties of MatLAB graphic objects. However, you can only access a subset ofobject properties through this mechanism. You may need to use a combination of interactive editing and command line editing to achieve the effect you desire 1-4
1 Overview of MATLAB Graphics 1-4 Editing Plots MATLAB formats a graph to provide readability, setting the scale of axes, including tick marks on the axes, and using color and line style to distinguish the plots in the graph. However, if you are creating presentation graphics, you may want to change this default formatting or add descriptive labels, titles, legends and other annotations to help explain your data. MATLAB supports two ways to edit the plots you create: • Using the mouse to select and edit objects interactively • Using MATLAB functions at the command-line or in an M-file Interactive Plot Editing If you enable plot editing mode in the MATLAB figure window, you can perform point-and-click editing of your graph. In this mode, you can change the format of objects in your graph by double-clicking on the object and changing the values of its properties. In plot editing mode, you access the properties through the a graphical user interface, called the Property Editor. For more information about interactive editing, see “Using Plot Edit Mode” on page 1-5. For information about editing object properties in plot editing mode, see “Using the Property Editor” on page 1-15. Using Functions to Edit Graphs If you prefer to work from the MATLAB command line or if you are creating an M-file, you can use MATLAB commands to edit the graphs you create. Taking advantage of the MATLAB Handle Graphics system, you can use the set and get commands to change the properties of the objects in a graph. Note Plot editing mode provides an alternative way to access the properties of MATLAB graphic objects. However, you can only access a subset of object properties through this mechanism. You may need to use a combination of interactive editing and command line editing to achieve the effect you desire
Using Plot Edit Mode Using Plot Edit Mode Use these toolbar buttons to add text arrows. and lines. To start plot edit mode click this button Use the Edit. Insert, and Eile Edit yiew Inse idols MindowHelp or edit existing objects in a Lotka Volterra Predator-Prey Population Mode Double-click on an object to select it Many Predators rey Population other objects by clicking and ill Increase Access object-specific plot Line yict edit functions through Line SMye Time t(Years) The MATLAB figure window supports a point-and-click style editing mode that rou can use to customize the appearance of your graph. This section describes how to start plot edit mode and perform basic editing tasks, including "Cutting, Copying, and Pasting Objects "on page 1-7 ·“ Moving and resizing Objects” on page1-7 1-8 “ Changing Your View of an Axes” on page1-13 15
Using Plot Edit Mode 1-5 Using Plot Edit Mode The MATLAB figure window supports a point-and-click style editing mode that you can use to customize the appearance of your graph. This section describes how to start plot edit mode and perform basic editing tasks, including: • “Selecting Objects in a Graph” on page 1-6 • “Cutting, Copying, and Pasting Objects” on page 1-7 • “Moving and Resizing Objects” on page 1-7 • “Editing Objects in a Graph” on page 1-8 • “Saving Your Work” on page 1-9 • “Changing Your View of an Axes” on page 1-13 To start plot edit mode, click this button. Use these toolbar buttons to add text, arrows, and lines. Use the Edit, Insert, and Tools menus to add objects or edit existing objects in a graph. Access object-specific plot edit functions through context-sensitive pop-up menus. Position labels, legends, and other objects by clicking and dragging. Double-click on an object to select it
I Overview of MatlaB graphics Starting Plot Edit Mode Before you can select objects in a figure by clicking on them, you must activate plot editing mode. There are several ways to activate plot edit mode Choose the edit Plot option on the figure window Tools menu Click on the selection button in the figure window toolbar Click this button to start plot edit mode Choose an option from the Edit or Insert menu. For example, if you choose the Axes Properties option on the Edit menu, MAtLAB activates plot edit mode and the axes appear selected. Run the plotedit command in the matlab command window When a figure window is in plot edit mode, the Edit Plot option on the Tool menu is checked and the selection button in the toolbar is highlighted Exiting plot Edit Mode To exit plot edit mode, click the selection button or click the Edit Plot option on the Tools menu. When plot edit mode is turned off, the selection button no longer highlighted Selecting Objects in a Graph To select an object in a graph 1 Start plot edit mode 2 Move the cursor over the object and click on it. Selection handles appear on the selected object Selecting Multiple Objects To select multiple objects at the same time 1 Start plot edit mode 1-6
1 Overview of MATLAB Graphics 1-6 Starting Plot Edit Mode Before you can select objects in a figure by clicking on them, you must activate plot editing mode. There are several ways to activate plot edit mode: • Choose the Edit Plot option on the figure window Tools menu. • Click on the selection button in the figure window toolbar. • Choose an option from the Edit or Insert menu. For example, if you choose the Axes Properties option on the Edit menu, MATLAB activates plot edit mode and the axes appear selected. • Run the plotedit command in the MATLAB command window. When a figure window is in plot edit mode, the Edit Plot option on the Tools menu is checked and the selection button in the toolbar is highlighted. Exiting Plot Edit Mode To exit plot edit mode, click the selection button or click the Edit Plot option on the Tools menu. When plot edit mode is turned off, the selection button is no longer highlighted. Selecting Objects in a Graph To select an object in a graph: 1 Start plot edit mode. 2 Move the cursor over the object and click on it. Selection handles appear on the selected object. Selecting Multiple Objects To select multiple objects at the same time: 1 Start plot edit mode. Click this button to start plot edit mode