Figures are the windows in which MATLAB displays graphics. Figures contain menus, toolbars, user-interface objects, context menus, axes and, as axes children, all other types of graphics objects.
MATLAB places no limits on the number of figures you can create. (Your computer systems might impose limitations, however.)
Figures play two distinct roles in MATLAB:
Figures can contain both graphs and GUIs components at the same time. For example, a GUI might be designed to plot data and therefore contain an axes as well as user interface objects.
[note]See Example — Using Figure Panels for an example of such a GUI.[/note]
The following diagram illustrates the types of objects that figures can contain.
Both figures and axes have children that act as containers. A uipanel can contain user interface objects and be parented to a figure and group objects (hggroup and hgtransform) can contain axes children (except light objects) and be parented to an axes.
See Objects That Can Contain Other Objects for more information.
MATLAB functions that draw graphics (e.g., plot and surf) create figures automatically if none exist. If there are multiple figures open, one figure is always designated as the “current” figure, and is the target for graphics output.
The gcf command returns the handle of the current figure or creates a new figure if one does not exist. For example, enter the following command to see a list of figure properties:
The root object CurrentFigure > property returns the handle of the current figure, if one exists, or returns empty if there are no figures open:
get(0,'CurrentFigure') ans = 
See Controlling Graphics Output for more information on how MATLAB determines where to display graphics.
Figures that display graphs need to contain axes to provide the frame of reference for objects such as lines and surfaces, which are used to represent data. These data representing objects can be contained in group objects or contained directly in the axes. See Example — Transforming a Hierarchy of Objects for an example of how to use group objects.
Figures can contain multiple axes arranged in various locations within the figure and can be of various sizes. See Automatic Axes Resize and Multiple Axes per Figure for more information on axes.
GUIs range from sophisticated applications to simple warning dialog boxes. You can modify many aspects of the figure to fit the intended use by setting figure properties. For example, the following figure properties are often useful when creating GUIs:
See the Figure Properties reference page for more information on figure characteristics you can specify.
See the Creating Graphical User Interfaces documentation for more information about using figure to create GUIs.
The parent of a figure is the root object. You cannot instantiate the root object because its purpose is only to store information. It maintains information on the state of MATLAB, your computer system, and some MATLAB defaults.
There is only one root object, and all other objects are its descendants. You do not create the root object; it exists when you start MATLAB. You can, however, set the values of root properties and thereby affect the graphics display.
[help]For more information, see Root Properties object properties.[/help]
See the figure reference page for information on creating figures.
See Callback Properties for Graphics Objects for information on figure events for which you can define callbacks.
See Figure Properties for information on other figure properties.