Graphics Objects (Handle Graphics) (MATLAB)

By this time, you have already explored many of MATLAB’s graphics capabilities. What you’ve done so far can be thought of as "high-level" graphics, i.e., it didn’t require you to get very deep into what was really going on in MATLAB. Nevertheless, we have already had to "slip" a little Handle Graphics in a few places in order to get the results we wanted. This topic however, marks your departure from the high-level use of MATLAB graphics, and begins your journey into a deeper understanding of the basic mechanism behind everything that happens in MATLAB. Here you will learn how to use "low-level" functions to manipulate every aspect of graphics objects. You will learn more about graphics objects and how to affect their properties, which will give you the knowledge you need to become a master MATLAB programmer.

All of the high-level graphics functions that have been discussed so far either create or manipulate graphics objects. The term "graphics object" may conjure up mental images of computer generated spheres or cubes, or it might bring to mind some of the objects that you have already created either with examples in this topic or on your own, such as lines (using plot, plot3, etc.), surfaces (created with surf, mesh, etc.), and text (using text, xlabel, etc.). However, you have already seen many other objects and probably didn’t even realize it. The computer screen, the individual Figure Windows, the axes, and images are all MATLAB graphics objects. As you proceed in this topic, you will learn more about these objects, as well as some more graphics objects such as user interface controls and user interface menus. You should think of these graphics objects as drawing primitives, i.e., the elementary building blocks that are used to generate plots that are more intricate in the Handle Graphics system.


In addition to the computer monitor’s screen, which is considered the root object, there are 12 other graphics object types.

The 12 low-level graphics functions that create graphics objects, as well as the root object which is present at the time you invoke MATLAB, are either the name of the object or an abbreviation of the name and are listed here in the following table.

Graphics

Object

Low-Level Creation Function

Description

Figure

figure or figure(H)

A window to show other graphics objects.

Axes

axes, axes(H), or axes(‘position’,RECT)

The axes for showing graphs in a figure.

Ulcontrol

Uicontrol

The user interface control is used to execute a function in response to the user.

Ulmenu

Uimenu

User defined menus in the figure.

Ulcontextmenu

uicontextmenu(‘PropertyName1 ‘,value1,..)

A pop-up menu that appears when a user right-clicks on a graphics object.

Image

image(C) or image(x,y,C)

A 2-D bitmap.

Light

light(‘PropertyName’/PropertyValue’,…)

Light sources that affect the coloring of patch and surface objects.

Line

line(x,y) or line(x,y,z)

A line in 2-D or 3-D plots.

Patch

patch(x,y,c) or patch(x,y,z,c)

A polygon that is filled with some color or texture and has edges.

Rectangle

rectangle, rectangle(‘Position’,[x,y,w,h]), or rectangle(‘Curvature’,[x,y],..)

A 2-D shape; can be rectangle or oval created within an axes object.

Surface

surface(X,Y,Z,C), surface(X,Y,Z), surface(Z,C), surface(Z)

3-D representation of data plotted as heights above the x-y plane.

Text

text(x,y,text_string) or text(x,y,z,text_string)

Character strings used in a figure.

The x, y, and z variables that define the coordinates of the line object are the arguments to the line graphics function. These variables can be either vectors or matrices. If the variables are matrices, an individual line object will be created for each column of data.

The x, y, and z variables that are passed to the patch function specify the vertex coordinates of the patch object. If the variables are matrices, the patch command will draw a polygon for each column of the matrices. The c variable is used to specify the color of the patch objects. For now, consider this variable to be defined as a RGB triplet or as a string to provide a uniform color across the polygon. Later we will present other forms of specifying the color.

Low-level surface object creation may use X, Y, and Z matrix variables to specify the corner points of the surface’s quadrilaterals. X and Y may also be vectors, in which case the length of X must be equal to the number of columns in Z and the length of Y must be equal to the number of rows in matrix Z. If provided, the matrix C defines the color of the surface object and must either be the same size as Z (size(C) = size(Z)) to allow for interpolated shading or have one less row and column (size(C) = size(Z)-1) for flat shading. We will see more about how to use the C matrix in a later topic.

Text object locations can be defined with the variables x, y, and z. By default, the string will be placed so that the first character is left justified and vertically centered about the point specified by the coordinate (x,y) or (x,y,z).

You cannot see light objects, but you can see their effects on patch and surface objects. They essentially specify light sources to which you can control style, color, and location. The properties of light objects will be discussed in this topic and in the next topic we will embark on an indepth exploration of light, color, and transparency.

There are two main advantages of using low-level graphics functions. The first is that they never clear the axes or alter any of the current attributes of the existing graphics. Recall that subsequent calls to the plot function would clear the current Figure Window (unless hold was set to on, or another Figure Window was open.) The second advantage is that you can pass property name/value pairs as additional arguments to these functions to control various aspects of the graphics objects at the time of creation. In Section 7.4 we will examine the different properties for each of the graphics objects, but first we shall explain how all these objects relate to each other in the graphics environment.

Next post:

Previous post: