| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
For More Information See MATLAB Graphics and 3-D Visualization in the MATLAB documentation for in-depth coverage of MATLAB graphics and visualization tools. Access these topics from the Help browser. |
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.
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:
Use plotting tools to create graphs interactively.
Use the command interface to enter commands in the Command Window or create plotting programs.
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.
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.
For More Information See Data Exploration Tools in the MATLAB Graphics documentation and Marking Up Graphs with Data Brushing, Making Graphs Responsive with Data Linking, Interacting with Graphed Data, and Opening the Basic Fitting GUI in the MATLAB Data Analysis documentation. |
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.
Note The data values that a line graph (for example) displays are copied into and become properties of the (lineseries) graphics object. You can, therefore, change the data in the workspace without creating a new graph. You can also add data to a graph. See Editing Plots for more information. |
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.
For More Information See Annotating Graphs in the MATLAB Graphics documentation, or select Annotating Graphs from the figure Help menu. |
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).
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.
For More Information See the print command reference page and Printing and Exporting in the MATLAB Graphics documentation, or select Printing and Exporting from the figure Help menu. |
There are two ways to save graphs that enable you to save the work you have invested in their preparation:
Save the graph as a FIG-file (select Save from the figure File menu).
Generate MATLAB code that can recreate the graph (select Generate M-File from the figure File menu).
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.
Note The states of any figure tools on the toolbars are not saved in a FIG-file; only the contents of the graph and its annotations are saved. The contents of datatips (created by the Data Cursor tool), are also saved. This means that FIG-files always open in the default figure mode. |
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.
For More Information See the print command reference page and Saving Your Work in the MATLAB Graphics documentation. |
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.

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.

For More Information See Plots and Plotting Tools in the MATLAB Graphics documentation, or select Plotting Tools from the figure Help menu. |
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 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.

For More Information See Anatomy of a Graph in the MATLAB Graphics documentation. |
Plotting tools are attached to figures and create an environment for creating graphs. These tools enable you to perform the following tasks:
Select from a wide variety of graph types.
Change the type of graph that represents a variable.
See and set the properties of graphics objects.
Annotate graphs with text, arrows, etc.
Create and arrange subplots in the figure.
Drag and drop data into graphs.
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:
Figure Palette — Specify and arrange subplots, access workspace variables for plotting or editing, and add annotations.
Plot Browser — Select objects in the graphics hierarchy, control visibility, and add data to axes.
Property Editor — Change key properties of the selected object. Click More Properties to access all object properties with the Property Inspector.
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.

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).

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.
For details on the many kinds of 2-D and 3-D graphs you can plot, see Types of MATLAB Plots in the MATLAB Graphics documentation. Clicking a function name opens the function reference pages. Several desktop tools also summarize the types of graphs available to you and help you plot them quickly. These tools, the Plot Selector and the Plot Catalog, are described in the following sections.
After you select variables in the Workspace Browser, you can
create a graph of the data by clicking the Plot Selector
toolbar
button. The Plot Selector icon depicts the type of graph it creates
by default. The default graph reflects the variables you select and
your history of using the tool. The Plot Selector icon changes to
indicate the default type of graph along with the function's name
and calling arguments. If you click the icon, the Plot Selector executes
that code to create a graph of the type it displays. For example,
when you select two vectors named t and y,
the Plot Selector initially displays plot(t,y).
If you click the down-arrow on the right side of the button, its menu opens to display all graph types compatible with the selected variables. The following figure shows the Plot Selector menu with an area graph selected. The graph types that the Plot Selector shows as available are consistent with the variables (t and y) currently selected in the Workspace Browser.

Releasing the mouse button over the highlighted icon creates an area graph.

You can see how the graph is created because the code the Plot Selector generates executes in the Command Window:
>> area(t,y,'DisplayName','t,y');figure(gcf)
You can also use the Plot Selector to get help for graphing functions. A scrolling yellow window pops up when you hover the mouse pointer over a Plot Selector menu item. The help window contains syntax descriptions for the function you point at. To open the entire function reference page in a Help Browser window, click the More Help link at the top right of the pop-up window, an example of which (for area) appears in the following figure.

To keep the help text visible, click just inside the top edge of the pop-up help window and drag it to another location on your screen. Close the window by clicking on the X in its upper left corner.
For more information about using the Plot Selector, see Creating Plots from the Workspace Browser.
Instead of the Plot Selector, you can use the Plot Catalog tool to browse graph types and create plots of selections of data. The Plot Catalog shows all graph types, categorizes them, and provides short descriptions of categories and plot types. It also lets you edit the list of variables before you create a plot. The Plot Catalog looks like this (when you select the Scatter Plots category).

Open the Plot Catalog in any of the following ways:
Open the Plot Selector menu and click the Catalog link at the bottom of the menu.
In the Workspace browser, right-click a selected variable and choose Plot Catalog from the context menu.
In the Variable Editor, select the values you want to graph, right- click the selection you just made, and choose Plot Catalog from the context menu.
If you are using the Figure Palette (a component of the Plotting Tools), right-click a selected variable and choose Plot Catalog from the context menu
The following illustration shows how you can open the plot catalog from the Figure Palette after selecting two numeric variables:

The menu of plot types above the Plot Catalog item is the same as your current Plot Selector list of "favorites." This means that you can specify these items to be the kinds of graphs that you regularly use. See Working with the Plot Selector GUI for more information on managing a list of favorite graph types.
After you select Plot Catalog, the Plot Catalog opens in a new, undocked window with the selected variables, ready for you to choose a type of graph to create. Select a plot category from the first column, then a graph type from the second column, 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.

For more information, see Example — Plotting from the Figure Palette.
![]() | Graphics | Editing Plots | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |