Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Making Objects Transparent

About Transparency

Making graphics objects semitransparent is a useful technique in 3-D visualization to make it possible to see an object, while at the same time, see what information the object would obscure if it was completely opaque. You can also use transparency as another dimension for displaying data, much the way color is used in MATLAB® Graphics.

The transparency of a graphics object determines the degree to which you can see through the object. You can specify a continuous range of transparency varying from completely transparent (i.e., invisible) to completely opaque (i.e., no transparency).

Objects that support transparency are

  • Image

  • Patch

  • Surface

The following picture illustrates the effect of transparency. The green isosurface (patch object) reveals the cone plot that lies in the interior.

    Note   You must have OpenGL® available on your system to use transparency. When rendering transparency MATLAB automatically uses OpenGL if it is available. If it is not available, transparency does not display. See the figure property RendererMode for more information.

Specifying Transparency

Transparency values, which range from [0 1], are referred to as alpha values. An alpha value of 0 means completely transparent (i.e., invisible); an alpha value of 1 means completely opaque (i.e., no transparency).

MATLAB treats transparency in a way that is analogous to how it treats color for the respective objects:

  • Patches and surfaces can define a single face and edge alpha value or use flat or interpolated transparency based on values in the figure's alphamap.

  • Images, patches, and surfaces can define alpha data that is used as indices into the alphamap or directly as alpha values.

  • Axes define alpha limits that control the mapping of object data to alpha values.

  • Figures contain alphamaps, which are m-by-1 arrays of alpha values.

See the following sections for more information on color:

Transparency Properties

The following table summarizes the object properties that control transparency.

PropertyPurpose

AlphaData

Transparency data for image and surface objects

AlphaDataMapping

Transparency data mapping method

FaceAlpha

Transparency of the faces (patch and surface only)

EdgeAlpha

Transparency of the edges (patch and surface only)

FaceVertexAlphaData

Patch only alpha data property

ALim

Alpha axis limits

ALimMode

Alpha axis limits mode

Alphamap

Figure alphamap

Transparency Functions

There are three functions that simplify the process of setting alpha properties.

FunctionPurpose

alpha

Set or query transparency properties for objects in current axes

alphamap

Specify the figure alphamap

alim

Set or query the axes alpha limits

Example — A Transparent Isosurface

Specifying a single transparency value for graphics objects is useful when you want to reveal structure that is obscured with opaque objects. For patches and surfaces, use the FaceAlpha and EdgeAlpha properties to specify the transparency of faces and edges. The following example illustrates this.

This example uses the flow function to generate data for the speed profile of a submerged jet within an infinite tank. One way to visualize this data is by creating an isosurface illustrating where the rate of flow is equal to a specified value.

[x y z v] = flow;
p = patch(isosurface(x,y,z,v,-3));
isonormals(x,y,z,v,p);
set(p,'facecolor','red','edgecolor','none');
daspect([1 1 1]);
view(3); axis tight; grid on;
camlight; lighting gouraud;

Adding transparency to the isosurface reveals that there is greater complexity in the fluid flow than is visible using the opaque surface. The statement

alpha(.5)

sets the FaceAlpha value for the isosurface face to .5.

Setting a Single Transparency Value for Images

For images, the statement

alpha(.5)

sets AlphaData to .5. When the AlphaDataMapping property is set to none (the default), setting AlphaData on an image causes the entire image to be rendered with the specified alpha value.

Was this topic helpful?