Graphics Objects Hierarchy (Handle Graphics) (MATLAB)

The MATLAB graphics system is an effective and powerful object oriented approach based on the simple paradigm of parent-child relationships between some of the objects. Each object has its own identity and characteristics as defined by its attributes or properties. In the previous section, some examples of the typical types of graphics objects that fall under each object category were presented; now we shall discuss how these objects relate to one another. In the next section, we will look at the properties of all the objects.

The parent-child relationship in MATLAB graphics is straightforward. Essentially, a child object cannot exist without the existence of its parent object. For example, before a surface object can be drawn, both a figure and an axes object must be present. Fortunately, you are not required to specifically create a parent object by typing the low-level graphic function in the Command Window (or by writing them in an M-file) before generating children objects. If the parent figure and axes objects are not present, MATLAB will automatically create them and then draw the surface object. Although you could very well create these objects yourself with,

tmpf059-1_thumb


you could have just typed

tmpf059-2_thumb

and MATLAB would create the figure and axes (assuming that another Figure Window was not already present). If you then close the Figure Window with the close command, neither the axes nor surface object will remain on the screen, since they cannot exist without their respective parents. Later we will learn about the delete command, which allows you to delete specific graphics objects from the set of objects contained within the current graphics environment. The primary point here is to understand that when a parent is deleted, so are its children.

So you might be wondering which graphics objects can be parents and which ones can only be children? The screen object is the most basic of all and is the foundation on which all other objects must rest. As previously mentioned, the screen object is referred to as the root object because the organization of graphics objects can be cast into a tree-like hierarchy, where, without the roots, the rest of the tree’s components are not able to survive or exist. Figure 7.1 depicts where the various graphics objects are in the hierarchical tree.

The graphics objects hierarchy tree.

Figure 7.1 The graphics objects hierarchy tree.

Figure Objects are the windows in which all other graphics objects are displayed. High-level graphics functions, e.g., plot, will automatically create a Figure Window if one is not already present. They can also be invoked with the command figure. In fact you have already been relying on Handle Graphics for, as you have already seen, you must use this command to create multiple Figure Windows. The Figure Window is a child of the root object, i.e., the screen object. The root object can be the parent to as many Figure Windows as you want, provided your computer system has enough memory. When there are multiple figure objects displayed, subsequent calls to the plot function will create plots in the current figure, i.e., the last Figure Window on which an action was made. The simplest way to make a given Figure Window the current one is to explicitly select it with

figure(figure_number)

where figure_number is the integer displayed in the border at the top of the Figure Window. The current Figure Window is the one which subsequent graphics commands will affect.

Figure objects have four different types of children. The children can be either a type of user interface object, specifically user interface control (Ulcontrol), user interface menu (Ulmenu), and user context menu (Ulcontextmenu), or axes objects. A figure can have multiple children, and not all its children need be of the same type.

The UIcontrol objects are used to generate graphical user interface controls. Their positions can be over any region of the Figure Window. There are various styles of controls that can be defined and each UIcontrol style allows a user to provide MATLAB with input data or a stimulus for initiating the execution of a predetermined set of actions. The UImenu objects are used to generate graphical user interface menus. UImenus appear at the top of the Figure Window when using MATLAB on X-Windows and MS-Windows systems. On a Macintosh system, the menu objects that are children of the current figure will appear at the top of the screen (by default, the menus provided by MATLAB and the system software will also appear). However, no matter what system you are using, these menus are children of a specific figure. The UIcontextmenu objects are used to generate menus that appear when a user right-clicks on a graphics object.

An axes object specifies a region of the Figure Window that will contain any collection of the seven axes children. In the previous topic, we saw that the subplot command could be used to designate multiple regions in the Figure Window for displaying multiple plots in the same Figure Window. Essentially, this high-level command creates an axes object in a location which is dependent on the input arguments. The axes object can be the parent to line, patch, surface, rectangle, image, light, and text objects. Instead of having high-level commands create an axes object, they can also be created explicitly with the axes function.

Line objects are the basic drawing primitives used to create 2-D and 3-D plots and contours. Specifically, they are used by the plot, plot3, contour, contour3, ezplot, fplot, and other specialized high-level commands. These objects do not have any children, but can have many siblings, which do not necessarily need to be other line objects.

Patch objects can also be used in both 2-D and 3-D contexts (unlike images they can be viewed from any perspective). These objects are usually thought of as filled polygons whose edge and face colors can be independently defined. Their colors can be defined with either a solid or an interpolated color or even with no color (making them transparent). These objects have no children, but since they are children of axes objects they can have line, surfaces, text, and other patch objects as siblings.

Surface objects are used to visualize data in a 3-D perspective. A surface is generated with a set of colored quadrilaterals, where each individual quadrilateral is very similar to a patch object. The edge and face colors can also be defined as solid, interpolated, or transparent. Usually the colors are related to the height of the object, but this need not be the case. These objects have no children, but may accompany other line, patch, surface, and text objects in their axes parent. They can be created with commands that create mesh and surf type graphics, in addition to pcolor (which will be discussed later).

Rectangle objects are 2-dimensional objects that have four sides and corners that have a specific roundness or "curvature." This type of object, created with the function rectangle, includes square-cornered rectangles, rounded rectangles, and ellipses. Rectangle objects, like image objects, can only be viewed in 2-D.

Image objects can be viewed only in a 2-D perspective; if you attempt to view them from any other perspective, they will not appear. Images are graphical representations of matrix data, where each matrix element value defines the color of a particular rectangle in the image. More specifically, the element is an index that points to one color within a list of colors (usually referred to as a color map) stored in the figure object. These objects are children of axes objects and therefore can be visualized with other axes children as long as the axes object is viewed from a 2-dimensional perspective. The image objects are displayed with the image or imagesc function.

Light objects are created using the light function, but are not objects that can be viewed in a plot directly. Instead, light objects affect the appearance of other objects in a plot. Specifically, light objects affect how surface and patch objects look, and have properties that include color, style, position, etc.

Finally, there are text objects. These character strings provide descriptive information to the plot. They can be used as axis labels or titles that are restricted in terms of their location with respect to the axes object. They can be character strings that are placed interactively with the plot editing tools available in the Figure Window, automatically by high-level commands such as clabel or legend, or they can be manually placed by either defining their location with a MATLAB command such as text or even with the mouse pointer such as by using gtext. These objects are children of axes objects and have no children themselves. Figure 7.2 shows a Figure Window with a typical collection of graphics objects.

A typical collection of graphics objects.

Figure 7.2 A typical collection of graphics objects.

In order to manipulate the characteristics or properties of these graphics objects with low-level graphics commands, you need to have some way of addressing each object. Previously, it was mentioned that The MathWorks coined the term "Handle Graphics" for the graphics system used by MATLAB. Handles provide the user with a way of identifying the graphics object that you want information about or whose information you want to alter. The next section further discusses the relevance of graphics object handles and how they can be obtained.

Next post:

Previous post: