Plotting Tools — Interactive Plotting
What Are Plotting Tools?
The modular, interactive plotting environment called plotting tools enables you to
- Create various type of graphs
- Select variables to plot directly from a workspace browser
- Easily create and manipulate subplots in the figure
- Add annotations such as arrows, lines, and text
- Set properties on graphics objects
You can open and configure plotting tools in many ways. To create a figure with the plotting tools attached, use the plottools command. You can also start the plotting tools from the figure toolbar by clicking the Show Plot Tools icon .
Remove the plotting tools from a figure using the Hide Plot Tools icon .
You can display the three basic plotting tools from the View menu by selecting Figure Palette, Plot Browser, or Property Editor .
The next section describes the individual components making up the plotting tools.
Plotting Tools Interface Overview
The Plotting Tools interface includes three panels that are associated with a figure.
- Figure Palette — Use to create and arrange subplot axes, view and plot workspace variables, and add annotations. Display the Figure Palette using the figurepalette command.
- Plot Browser — Use to select and control the visibility of the axes or graphic objects plotted in the figure. You can also add data to any selected axes by clicking the Add Data button. Display the Plot Browser using the plotbrowser command.
- Property Editor — Use to set common properties of the selected object. You can also open the Property Editor using the propertyeditor command. In the Property Editor you can click the More Properties button to display the Property Inspector, a GUI that displays most object properties and allows you to change any property’s value (unless it is read-only). See Accessing Object Properties with the Property Inspector for details.
The example illustrated below shows the plotting tools attached to a figure containing two subplots of lineseries data. The code to produce the graphs is
x = 0:pi/100:2*pi; y1 = sin(x); y2 = sin(x+.25); y3 = sin(x+.5); subplot(2,1,1); plot(x,y1,x,y2,x,y3); axis tight; w1 = cos(x); w2 = cos(x+.25); w3 = cos(x+.5); subplot(2,1,2); plot(x,w1,x,w2,x,w3); axis tight;
You summon the plotting tools, either by selecting Figure Palette, Plot Browser, and Property Editor from the figure’s View menu, or by typing
in the Command Window. Typing plottools or plottools on restores the configuration of tools the last time you were using them; use the View menu to show the ones you need and hide the ones you do not, and the mouse to dock and undock them. The default configuration of plotting tools is shown below. MATLAB preferences remember the current arrangement of plot tools — whether they are visible or not — each time you exit; if you want to revert to the default configuration you need to restore the arrangement shown below manually.
Each of the plotting tools shown above can be docked or undocked from its figure, or dismissed by clicking the x at the right end of its titlebar. If you dismiss a tool and want it back again, you can raise it from the View menu or by typing one of several commands. For instance, if you had undocked, and then dismissed the figure palette, you could type either
plottools( ‘on’, ‘figurepalette’) or
Your desktop configuration might then look like this:
Figures Groups. When you activate any plot tool for a figure (or dock the figure in the desktop), the figure becomes part of a Figures group. Figures groups are desktop containers that you can dock in your desktop. Individual figures are not dockable except within the Figures group container. If you create subsequent figures, they will also dock in the Figures group, where they can be panelled or overlapped for viewing. A row of tabs appears along the bottom, one for each figure in the group.
When you dock a plot tool in a figure group and then dock the figure group in the desktop, the tool is included in that section of the desktop as well, as the following illustration shows:
Working with Multiple Figures. When you create a new figure and plot into it, It is created without plotting tools enabled, even if another figure already has them open:
This generates a freestanding plot, like this:
If you then open the plotting tools for the figure by clicking the Open Plotting Tools icon , the figure docks in the figure window:
The new figure might seem to disappear if the Figures window is hidden, but it will overlay the existing plot within that window (it does not replace it). You can switch between the two figures by clicking the tabs at the bottom of the figure area. Be aware that clicking the x on the right side of a figure’s tab deletes that figure entirely, without asking for confirmation.
If you want to see both figures at once, use the Tiling Palette at the upper right corner of the Figures window to arrange the figures. For example, clicking the Left/Right tiling tool lays out the two figures side by side:
As the above illustrations shows, plot objects can be selected in both figures, but only one figure has focus at a time.
The Figure Palette
The Figure Palette contains three panels. Select the panel you want to view by clicking the respective button, which twists down the panel and exposes its contents.
The Figure Palette enables you to perform the following tasks with these panels:
- New Subplots — Add 2-D or 3-D axes to the figure.
- Variables — Browse and plot workspace variables.
- Annotations — Add annotations to graphs.
Adding Subplot Axes
The New Subplots panel enables you to create a grid of either 2-D or 3-D axes. To display the selector, click the grid icon next to the axes type. A subplot selector grid appears.
As you move the cursor, squares darken to indicate the layout of axes that will be created if you release the mouse button. Click Cancel at the bottom of the grid to leave the figure unchanged.
The picture above shows the New Subplots panel selected to display four equally sized axes in the figure. Existing axes resize as required to accommodate the new layout.
The Variables panel displays current workspace variables. Double-clicking a variable in this panel opens that variable in the Variable Editor. If you select a variable and right-click to display the context menu, you can select a graphics function to plot the variable.
For example, the following picture illustrates how to plot the columns of variable Z. This is equivalent to passing a matrix to the plot function.
The context menu contains a list of possible plot types based on the variable you select and also enables you to perform certain operation on the variable, such as opening it in the Variable Editor, saving, copying, and so on.
The context menu items may change when you select different variables because a particular variable might be incompatible some of the plot types.
You can also drag the variable directly into an axes, in which case MATLAB selects the first appropriate plot type for that variable. If there are multiple axes, you must first select the one you want to plot in and then drag the variable to that axes.
In the previous example, the variable Z would be plotted using the plot function if you were to drag it into an axes.
If the desired plotting function is not available from the context menu, you can select More Plots to display the Plot Catalog tool.
The Plot Catalog tool provides access to most of the MATLAB plotting functions. You can type any workspace variables or MATLAB expressions in the Plotted Variables field, which are then passed to the selected plotting function as arguments. Separate variables with a comma.
You can also enter function handles to pass to one of the “ez…” family of plotting functions from the Analytic Plots category.
[warning]The Plot Catalog does not prevent you from passing inappropriate or insufficient data to a plotting function; if the plot appears to be incorrect or if a plot fails to draw after you press Plot or Plot in New Figure, you should check the Command Window for warning and error messages.[/warning]
The following picture shows the Plot Catalog tool and describes its components.
The Annotations panel enables you to insert annotation objects into a plot. To add an object, first select the object you want to add, and then click and drag the mouse to position and size the object.
See How to Annotate Graphs for more information about the various types of annotation objects.
The Plot Browser
The Plot Browser provides a legend of all the graphs in the figure. It lists each axes and the objects (lines, surfaces, etc.) used to create the graph.
For example, suppose you plot an 11-by-11 matrix z. The plot function creates one line for each column in z.
When you set the DisplayName property, the Plot Browser indicates which line corresponds to which column.
If you want to set the properties of an individual line, double-click on the line in the Plot Browser. Its properties are displayed in the Property Editor, which opens on the bottom of the figure.
You can select a line in the graph, and the corresponding entry in the Plot Browser is highlighted, enabling you to see which column in the variable produced the line.
The check box next to each item in the Plot Browser controls the object’s visibility. For example, suppose you want to plot only certain columns of data in z, perhaps the positive values. You can deselect the columns you do not want to display. The graph updates as you deselect each box and rescales the axes as required.
You can delete any selected item in the Plot Browser by selecting Delete from the right-click context menu.
The Plot Browser provides the mechanism by which you add data to axes. The procedure is as follows:
- Select a 2-D or 3-D axes from the New Subplots subpanel.
- After creating the axes, select it in the Plot Browser panel to enable the Add Data button at the bottom of the panel.
- Click the Add Data button to display the Add Data to Axes dialog.
The Add Data to Axes dialog enables you to select a plot type and specify the workspace variables to pass to the plotting function. You can also specify a MATLAB expression, which is evaluated to produce the data to plot.
Selecting Workspace Variables to Create a Graph. Suppose you want to create a surface graph from three workspace variables defining the XData, YData, and ZData (see the surf function for more information on this type of graph).
In the workspace you have defined three variables, x, y, and z. To create the graph, configure the Add Data to Axes dialog as shown in the following picture.
Using a MATLAB Expression to Create a Graph. The following picture shows the Add Data to Axes dialog specifying a workspace variable x for the plot’s x data and a MATLAB expression (x.^2 + 3*x + 5) for the y data.
You can use the default X Data value of index if you do not want to specify x data. In this case, the y data versus the index of the y data values are plotted, which is equivalent to calling the plot command with only one argument.
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.
Ways to Display the Property Editor
There are a variety of ways to display the Property Editor:
- Double-click an object when plot edit mode is enabled.
- Select an object and right-click to display its context menu, then select Properties.
- Select Property Editor from the View menu.
- Use the propertyeditor command.
Changing Plot Types
You can use the property editor to change the type of plot used to display data. For example, you can change the following line graph to a stem, stairs, area, or bar graph by changing the Plot Type field.
Accessing Object Properties with the Property Inspector
The Property Editor enables you to change the most commonly used object properties. To access more object properties, use the Property Inspector. Open the Property Inspector by clicking the More Properties button on the Property Editor or by typing inspect in the Command Window. The following picture shows the Property Inspector displaying the properties of the same lineseries object as that in the previous picture.
The default view of properties is an alphabetic list; you can change to a tree view by clicking the icon in the upper left corner containing plus marks. Click the “AZ” icon to its right to return to an alphabetized list view. Properties that contain fields, such as RGB color components, have a plus mark to their left you can click to expose the individual values. You can change properties that have enumerated values, such as Marker, via drop-down lists (downward-pointing triangles on the right edge of the inspector window). The following figure shows the Marker property being set to diamond using the Property Inspector (note the tree view in which other groups of properties have been collapsed):
There are a few properties of objects that the Property Inspector does not show, for example Parent and Children. For complete descriptions of the properties of graphics objects, use the Handle Graphics Property Browser.
Getting Help for Object Properties
If you are not sure what a property does or what values it can take on, you can get a description of it from the Property Inspector. To do so, right-click on the name or values of a property and select What’s This from the popup menu; a Help window opens displaying the property reference page for the current object, scrolled to the property you clicked. The following picture shows how this works:
If you want to access the properties of light or uicontextmenus objects, you need to get the handle using MATLAB commands, because you cannot click on these objects.
For example, to get the handles of all light objects in the current axes, use findobj.
h = findobj(gca,'Type','light');
Then use the inspect command to display the Property Inspector.
inspect(h) % Inspect all light objects inspect(h(1)) % Inspect the first light object in list