Figures, Plots, and Graphs

What Is a MATLAB® Graph?

The MATLAB® environment offers you a variety of data plotting functions plus a set of GUI tools to create, and modify graphic displays. The GUI tools afford most of the control over graphic properties and options that typed commands such as annotate, get, and set provide.

A figure is a MATLAB window that contains graphic displays (usually data plots) and UI components. You create figures explicitly with the figure function, and implicitly whenever you plot graphics and no figure is active. By default, figure windows are resizable and include pull-down menus and toolbars.

A plot is any graphic display you can create within a figure window. Plots can display tabular data, geometric objects, surface and image objects, and annotations such as titles, legends, and colorbars. Figures can contain any number of plots. Each plot is created within a 2-D or a 3-D data space called an axes. You can explicitly create axes with the axes or subplot functions.

A graph is a plot of data within a 2-D or 3-D axes. Most plots made with MATLAB functions and GUIs are therefore graphs. When you graph a one-dimensional variable (e.g., rand(100,1)), the indices of the data vector (in this case 1:100) become assigned as x-values, and plots the data vector as y-values. Some types of graphs can display more than one variable at a time, others cannot.

The contents and varieties of figures, plots and graphs that MATLAB can make are explained in the following sections.

Anatomy of a Graph

MATLAB plotting functions and tools direct their output to a figure window. Each figure is a separate window that you can dock in the desktop, and collect together with other plots in a Figure Group. To illustrate the basic components of a graph, execute the following M-code to create a plot of a family of sine curves:

x = [0:.2:20];
y = sin(x)./sqrt(x+1);
y(2,:) = sin(x/2)./sqrt(x+1);
y(3,:) = sin(x/3)./sqrt(x+1);
plot(x,y)

The resulting figure contains a 2-D set of axes and looks like this:

Some of the components and tools of figure windows are called out below:

The plot function uses a default line style and color to distinguish the data sets plotted in the graph. You can change the appearance of these graphic components or add annotations to the graph to present your data in a particular way.

Figure Toolbars

Figure toolbars provide shortcuts to access commonly used features. These include operations such as saving and printing, plus tools for interactive zooming, panning, rotating, querying, and editing plots. The following picture shows the features available from this toolbar.

Note that you can enable two other toolbars from the View menu:

Types of MATLAB® Plots

You can construct a wide variety of 2-D and 3-D MATLAB plots with very little, if any, programming required on your part. The following two tables classify and illustrate most of the kinds of plots you can create. They include line, bar, area, direction and vector field, radial, and scatter graphs. They also include 2-D and 3-D functions that generate and plot geometric shapes and objects. Most 2-D plots have 3-D analogs, and there are a variety of volumetric displays for 3-D solids and vector fields. Plot types that begin with "ez" (such as exsurf) are convenience functions that can plot arguments given as functions.

Two-Dimensional Plotting Functions

The table below shows all available MATLAB 2-D plot functions. If you are reading this online, you can click any icon to see the documentation for that function. Techniques for using many of the functions are also discussed in later sections of this document.

Line GraphsBar GraphsArea GraphsDirection GraphsRadial GraphsScatter Graphs

plot

bar (grouped)

area

feather

polar

scatter

plotyy

barh (grouped)

pie

quiver

rose

spy

loglog

bar (stacked)

fill

comet

compass

plotmatrix

semilogx

barh (stacked)

contourf

 

ezpolar

 

semilogy

hist

image

   

stairs

pareto

pcolor

   

contour

errorbar

ezcontourf

   

ezplot

stem

    

ezcontour

     

Three-Dimensional Plotting Functions

The table below shows all available MATLAB 3-D and volumetric plot functions. It includes functions that generate 3-D data (cylinder, ellipsoid, sphere), but most plot either arrays of data or functions. If you are reading this online, you can click any picture in the table to see the documentation for that function. For information about and examples of using 3-D plotting functions, see Creating 3-D Graphs in the 3-D Visualization documentation.

Line GraphsMesh Graphs and Bar GraphsArea Graphs and Constructive ObjectsSurface GraphsDirection GraphsVolumetric Graphs

plot3

mesh

pie3

surf

quiver3

scatter3

contour3

meshc

fill3

surfl

comet3

coneplot

contourslice

meshz

patch

surfc

streamslice

streamline

ezplot3

ezmesh

cylinder

ezsurf

 

streamribbon

waterfall

stem3

ellipsoid

ezsurfc

 

streamtube

 

bar3

sphere

   
      
 

bar3h

    

Choosing a Plot Type with the Plot Catalog

Most of the plotting functions shown in the previous tables are accessible through the Figure Palette, one of the Plot Tools you can access via the figure window View menu. When the Figure Palette is active and you select one, two or more variables listed within it, you can generate a plot of any appropriate type by right-clicking and selecting a plot type from the context menu that appears. The lowest item on that menu is More Plots. When you select More Plots, the Plot Catalog opens for you to browse through all plot types and generate one of them, either to display the variables you selected in the Figure Palette or a MATLAB expression you can specify in the Plot Catalog window. For more information, see The Figure Palette.

  


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