Overview of Plotting

Plotting Process

The MATLAB environment provides a wide variety of techniques to display data graphically. Interactive tools enable you to manipulate graphs to achieve results that reveal the most information about your data. You can also annotate and print graphs for presentations, or export graphs to standard graphics formats for presentation in Web browsers or other media.

The process of visualizing data typically involves a series of operations. This section provides a "big picture" view of the plotting process and contains links to sections that have examples and specific details about performing each operation.

Creating a Graph

The type of graph you choose to create depends on the nature of your data and what you want to reveal about the data. You can choose from many predefined graph types, such as line, bar, histogram, and pie graphs as well as 3-D graphs, such as surfaces, slice planes, and streamlines.

There are two basic ways to create MATLAB graphs:

You might find it useful to combine both approaches. For example, you might issue a plotting command to create a graph and then modify the graph using one of the interactive tools.

Exploring Data

After you create a graph, you can extract specific information about the data, such as the numeric value of a peak in a plot, the average value of a series of data, or you can perform data fitting. You can also identify individual graph observations with Datatip and Data brushing tools and trace them back to their data sources in the MATLAB workspace.

Editing the Graph Components

Graphs are composed of objects, which have properties you can change. These properties affect the way the various graph components look and behave.

For example, the axes used to define the coordinate system of the graph has properties that define the limits of each axis, the scale, color, etc. The line used to create a line graph has properties such as color, type of marker used at each data point (if any), line style, etc.

Annotating Graphs

Annotations are the text, arrows, callouts, and other labels added to graphs to help viewers see what is important about the data. You typically add annotations to graphs when you want to show them to other people or when you want to save them for later reference.

Printing and Exporting Graphs

You can print your graph on any printer connected to your computer. The print previewer enables you to view how your graph will look when printed. It enables you to add headers, footers, a date, and so on. The print preview dialog box lets you control the size, layout, and other characteristics of the graph (select Print Preview from the figure File menu).

Exporting a graph means creating a copy of it in a standard graphics file format, such as TIFF, JPEG, or EPS. You can then import the file into a word processor, include it in an HTML document, or edit it in a drawing package (select Export Setup from the figure File menu).

Adding and Removing Figure Content

By default, when you create a new graph in the same figure window, its data replaces that of the graph that is currently displayed, if any. You can add new data to a graph in several ways; see Adding More Data to the Graph for how to do this using a GUI. You can manually remove all data, graphics and annotations from the current figure by typing CLF in the Command Window or by selecting Clear Figure from the figure's Edit menu.

Saving Graphs for Reuse

There are two ways to save graphs that enable you to save the work you have invested in their preparation:

FIG-Files.   FIG-files are a binary format that saves a figure in its current state. This means that all graphics objects and property settings are stored in the file when you create it. You can reload the file into a different MATLAB session, even when you run it on a different type of computer. When you load a FIG-file, a new MATLAB figure opens in the same state as the one you saved.

Generated Code.   You can use the MATLAB M-code generator to create code that recreates the graph. Unlike a FIG-file, the generated code does not contain any data. You must pass appropriate data to the generated function when you run the code.

Studying the generated code for a graph is a good way to learn how to program using MATLAB.

Graph Components

MATLAB graphs display in a special window known as a figure. To create a graph, you need to define a coordinate system. Therefore, every graph is placed within axes, which are contained by the figure.

You achieve the actual visual representation of the data with graphics objects like lines and surfaces. These objects are drawn within the coordinate system defined by the axes, which appear automatically to specifically span the range of the data. The actual data is stored as properties of the graphics objects.

See Understanding Handle Graphics® Objects for more information about graphics object properties.

The following picture shows the basic components of a typical graph. You can find commands for plotting this graph in Preparing Graphs for Presentation.

Figure Tools

The figure is equipped with sets of tools that operate on graphs. The figure Tools menu provides access to many graph tools, as this view of the Options submenu illustrates. Many of the options shown in this figure also appear as context menu items for individual tools such as zoom and pan. The figure also shows three figure toolbars, discussed in Figure Toolbars.

Accessing the Tools

You can access or remove the figure toolbars and the plotting tools from the View menu, as shown in the following picture. Toggle on and off the toolbars you need. Adding a toolbar stacks it beneath the lowest one.

Figure Toolbars

Figure toolbars provide easy access to many graph modification features. There are three toolbars. When you place the cursor over a particular tool, a text box pops up with the tool name. The following picture shows the three toolbars displayed with the cursor over the Data Cursor tool.

Plotting Tools

Plotting tools are attached to figures and create an environment for creating graphs. These tools enable you to perform the following tasks:

Display the plotting tools from the View menu or by clicking the Show Plot Tools icon in the figure toolbar, as shown in the following picture.

You can also start the plotting tools from the MATLAB prompt:

plottools

The plotting tools are made up of three independent GUI components:

You can also control these components from the Command Window, by typing the following:

figurepalette
plotbrowser
propertyeditor

See the reference pages for plottools, figurepalette, plotbrowser, and propertyeditor for information on syntax and options.

The following picture shows a figure with all three plotting tools enabled.

Using Plotting Tools and MATLAB® Code

You can enable the plotting tools for any graph, even one created using MATLAB commands. For example, suppose you type the following code to create a graph:

t = 0:pi/20:2*pi;
y = exp(sin(t));
plotyy(t,y,t,y,'plot','stem')
xlabel('X Axis')
ylabel('Plot Y Axis')
title('Two Y Axes')

This graph contains two y-axes, one for each plot type (a lineseries and a stemseries). The plotting tools make it easy to select any of the objects that the graph contains and modify their properties.

For example, adding a label for the y-axis that corresponds to the stem plot is easily accomplished by selecting that axes in the Plot Browser and setting the Y Label property in the Property Editor (if you do not see that text field, stretch the Figures window to make it taller).

Arranging Graphs Within a Figure

You can place a number of axes within a figure by selecting the layout you want from the Figure Palette. For example, the following picture shows how to specify four 2-D axes in the figure.

Select the axes you want to target for plotting. You can also use the subplot function to create multiple axes.

Choosing a Type of Graph to Plot

The many kinds of 2-D and 3-D graphs you can make are described in Types of MATLAB® Plots in the MATLAB Graphics documentation. Almost all plot types are itemized, described, and illustrated by a tool called the Plot Catalog. You can use the Plot Catalog to browse graph types, choose one to visualize your selected variables, and then create it in the current or a new figure window. You can access the Plot Catalog by selecting one or more variables, as follows:

The icon on the plot selector tool represents a graph type, and changes depending on the type and dimensionality of the data you select. It is disabled if you select no data or nonnumeric data.

The following illustration shows how you can open the plot catalog from the Figure Palette:

The Plot Catalog opens in a new, undocked window with the selected variables ready to plot, after you select a plot type and click Plot or Plot in New Figure. You can override the selected variables by typing other variable names or MATLAB expressions in the Plotted Variables edit field.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS