Interactive Plotting in MATLAB Matlab Help

  • Interactive Plotting in MATLAB
    This is an optional section that may be omitted without affecting your understanding of the material in subsequent sections and chapters. The graphics functions covered in Sections 5~1 through 5.3 are powerful enough to create detailed, professional-looking plots in MATLAB, and they can be placed in reusable script files to create similar plots. This feature gives them an advantage over the interactive plotting interface discussed in this section. This interface can, however, can be advantageous in situations where: .
    • You need to create a large number of different types of plots,
    • You must construct plots involving many data sets,
    • You want to add annotations such as rectangles and ellipses, or
    • You want to change plot characteristics such as tick spacing, fonts, bolding, italics, and colors. The interactive plotting environment in MATLAB is a set of tools for:
    • Creating different types of graphs,
    • Selecting variables to plot directly from the Workspace Browser,
    • Creating and editing subplots,• . Adding annotations such as lines, arrows, text, rectangles, and ellipses, and
    • Editing properties of graphics objects, such as their color, line weight, and font. The Plot Tools interface includes the following three panels associated with the given figure.
    • The Figure Palette: Use this to create and arrange subplots, to view and plot workspace variables, and to add annotations.
    • The Plot Browser: Use this to select and control the visibility of the axes or graphics objects plotted in the figure, and to add data for plotting.
    • The Property Editor: Use this to set basic properties of the selected object and to obtain access to all properties through the Property Inspector. Space limitations prevent us from discussing in detail all the features of the MATLAB interactive plotting environment. The following overview, however,
    should be sufficient to get you started. It is recommended that as you read this section you follow along and perform the steps in MATLAB. Note that selecting Help from the Figure window enables you to go directly to graphics-specific
    sections of the MATLAB help.• . Adding annotations such as lines, arrows, text, rectangles, and ellipses, and
    • Editing properties of graphics objects, such as their color, line weight, and font. The Plot Tools interface includes the following three panels associated with a given figure.
    • The Figure Palette: Use this to create and arrange subplots, to view and
    plot workspace variables, and to add annotations.
    • The Plot Browser: Use this to select and control the visibility of the axes
    or graphics objects plotted in the figure, and to add data for plotting.
    • The Property Editor: Use this to set basic properties of the selected object and to obtain access to all properties through the Property Inspector. Space limitations prevent us from discussing in detail all the features of the MATLAB interactive plotting environment. The following overview, however,
    should be sufficient to get you started. It is recommended that as you read this section you follow along and perform the steps in MATLAB. Note that selecting Help from the Figure window enables you to go directly to graphics-specific
    sections of the MATLAB help.

    The Figure Window
    When yo~ create a plot, the Figure window appears with the Figure toolbar visible (see Figure 5.4-1). This window has eight menus. The File Menu The File menu is used for saving and printing the figure. This menu was discussed in Section 5.1 under Saving Figures and Exporting Figures.
    The Edit Menu You can use the Edit menu to cut, copy, and paste items, such as legend or title text, that appear in the figure. Click on Figure Properties to open the Property Editor-Figure dialog box to Change certain properties of the figure.
    Three items on the Edit menu are very useful for editing the figure. Clicking the Axes Properties item brings up the Property Editor-Axes dialog box. Double-clicking on-any axis also brings up this box. You can change the scale
    type (linear, log, etc.), the labels, and the tick marks by selecting the tab for the desired axis or the font to be edited.
    The Current Object Properties item enables you to change the properties of an object in the figure. To do this, first click on the object, such as a plotted line, then click on Current Object Properties in the Edit menu. You will see the Property Editor-Line series dialog box that lets you change properties such
    as line weight and color, data-marker type, and plot type.
    Clicking on any text, such as that placed with the title, x label, ylabel, legend, or g text commands, then selecting Current Object Properties in the Edit menu brings up the Property Editor-Text dialog box, which enables you to edit the text.

The Figure window with the Figure toolbar displayed

The Figure window with the Figure toolbar displayed

The View Menu The items on the View menu are the three toolbars (Figure toolbar, Plot Edit toolbar, and Camera toolbar), the Figure Palette, the Plot Browser, and the Property Editor. These will be discussed late f in this section. The Insert Menu The Insert menu enables you to insert labels, legends, titles, text, and drawing objects, rather than using the relevant commands from the Command window. To insert a label on the y-axis, for example, click on the Y Label item on the menu; a box will appear on the y-axis. Type the label in this box, and then click outside the box to finish. The Insert menu also enables you to insert arrows, lines, text; rectangles, and ellipses in the figure. To insert an arrow, click on the Arrow item; the mouse cursor changes to a cros shair style. Then Click the mouse button, and move the cursor to create the arrow. The arrowhead will appear at the point where you release the mouse button. Be sure to add arrows, lines, and other annotations only after you are finished moving or resizing your axes, because these objects are not anchored to the axes. (They can be anchored to the plot by pinning; see the MATLAB help.) To delete or move a line or arrow, click on it, then press the Delete key to delete it, or press the mouse button and move it to the desired location. The Axes item lets you use the mouse to place a new set of axes within the existing plot .issued from the Command window will direct the output to these axes. The Light item applies to 3D plots. The Tools Menu The Tools menu includes items for adjusting the view (by zooming and panning) and the alignment of objects on the plot. The Edit Plot  item starts the plot editing mode, which can also be started by clickin on the northwest-facing arrow on the Figure toolbar. The Tools menu also gives access to the Data Cursor, which is discussed later in this section. The last two items, Basic Fitting and Data Statistics, will be discussed in Sections 5.7 and 7.1 respectively. /

Other Menus The Desktop menu enables you to dock the Figure window within the desktop. The Window menu lets you switch between the Command’window and any other Figure windows. The Help menu accesses the general MATLAB Help System, as well as help features specific to plotting. There are three toolbars available in the Figure window: the Figure toolbar, the Plot Edit toolbar, and the Camera toolbar. The’ View menu lets you select
which ones ‘you want to appear. We will discuss the Figure toolbar and the Plot Edit toolbar in this section. The Camera toolbar is useful for 3D plots, which are discussed at the end of this chapter

The Figure Toolbar
To activate the Figure toolbar, select it from the View menu (see Figure 5.4-1). The four left-most buttons are for opening, saving, and printing the figure. Clicking on the northwest-facing arrow button toggles the plot edit mode on and off. The Zoom-in and Zoom-out buttons let you obtain a close-up or faraway
view of the figure. The Pan and Rotate 3D buttons are used for 3D plots. The Data Cursor button enables you to read data directly from a graph by dis-. playing the values of points you select on plotted lines, surfaces, images, and so on. The Insert Color bar button inserts a color map strip in the graph and is useful for 3D surface plots. The Insert Legend button enables you to insert a
legend in the plot. ‘
The Plot Edit Toolbar
Once a plot is in the window you can enable plot editing by clicking on the northwest-facing arrow on the Figure toolbar. Then double-click on ‘an axis, a plotted line, or a label to activate the appropriate property editor. Select Plot Edit toolbar from the View menu (see Figure 5.4-2). To add text that is not a label, title, or legend, click the button labeled T, move the cursor to the desired location for the text, click the mouse button, and type the text. When finished, click outside the text box and note that the nine left-most buttons become highlighted and available. These enable you to modify the color, font, and other attributes of the text. To insert arrows, lines, rectangles, and ellipses, click on the appropriate button and follow the instructions given previously for the Insert menu.

The Figure window with the Figure and Plot Edit tool bars displayed

The Figure window with the Figure and Plot Edit tool bars displayed

The Plot Tools
Once a figure has been created you can display any or all of the three Plot Tc (Figure Palette, Plot Browser, and Property Editor) by selecting them from View menu. You can also start the environment by first creating a plot and t clicking on the Show Plot Tools icon in the Figure toolbar (see Figure 5.4- or by creating a figure with the plotting tools attached by using the plot toe command. Remove the tools by clicking on the Hide Tools icon. Figure 5.4-3 shows the result of clicking on the plotted line before click in] Show Plot Tools icon. The plotting interface then displays the Property Editor Lineseries. . .
The Figure Palette
The Figure Palette contains three panels, which are selected and expande clicking the appropriate button. Click on the grid icon in the New Subplots I to display the selector grid that enables you to specify the layout of the sub plot the Variables panel you can select a graphics function to plot the variable by using the variable and right-clicking to display the context menu. This menu con a list of possible plot types based on the type of variable you select. You car
drag the variable into an axes set and MATLAB will select an appropriate plot

The Figure window with the Plot Tools activated.

The Figure window with the Plot Tools activated.

Selecting More Plots from the context menu activates the Plot Catalog tool, which provides access to most of the plotting functions. After selecting a plot category, and a plot type from that category, you will see its description in the right-most display. Type the name of a one or more variables in the Plotted Variables field, separated by commas, and they will be passed to the selected plotting function as arguments. You can also type a MATLAB expression that uses any workspace variables shown in the Figure Palette. Click on the Annotations panel to display a menu of objects such as lines, arrows, etc. Click on the desired object and use the mouse to position and size it.
The Plot Browser
The Plot Browser provides a legend of all the graphs in the figure. For example, if you plot an array with multiple rows and columns, the Browser lists each axis and the objects (lines, surfaces, etc.) used to create the graph. To set the properties of an individual line, double-click on the line, Its properties are displayed in the
Property Editor-Lineseries box, which opens on the bottom of the figure. If you select a line in the graph, the corresponding entry in the Plot Browser is highlighted, indicating which column ill the variable produced the line. The check box next to each item in the Browser controls the object’s visibility. For

example, if you want to plot only certain columns of data, you can uncheck the columns not wanted. The graph updates as you uncheck each box and rescale the axes as required.
The Property Editor
The Property Editor enables you to access a subset of the selected object’s properties. When no object is selected, the Property Editor displays the figure’s properties. There are several ways to display the Property Editor.
1. Double-click an object when plot edit mode is enabled.
2. Select an object and right-click to display its context menu, then select
Properties.
3. Select Property Editor from the Vi,ew menu.
4. Use the propertyedi tor command.
The Property Editor enables you to change the most commonly used obj properties. If you want to access all object properties, use the Property Inspect To display the Property Inspector, click the Inspector button on any Prope Editor panel. Use of this feature requires detailed knowledge of object propern
and handle graphics, and thus will not be covered here.
Recreating Graphs from M-Files
Once your graph is finished, you can generate MATLAB code to reproduce graph by selecting Generate M-File from the FiIe menu. MATLAB create function that recreates the graph and opens the generated M-File in the edi: This feature is particularly useful for capturing property settings and other functions made in the plot editor. You can also use the makem code function

Adding Data to Axes
The Plot Browser provides the mechanism by which you add data to axes. procedure is as follow:
1. Select a 2D or 3D axis from the New Subplots subpanel.
2. After creating the axis, select it in the Plot Browser panel to enable the
Data button at the bottom of the panel.
3. Click the-Add Data button to display the Add Data to Axes dialog box. Add Data to Axes dialog enables you to select a plot type and specify workspace variables to pass to the plotting function. You can also speci . a MATLAB expression, which is evaluated to produce the data to plot.

Posted on July 29, 2015 in advanced Plotting and Model Building

Share the Story

Back to Top
Share This