|On this page…|
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
The following picture illustrates the effect of transparency. The green isosurface (patch object) reveals the cone plot that lies in the interior.
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:
Specifying Patch Coloring in Creating 3-D Models with Patches in the Using MATLAB Graphics documentation
Coloring Mesh and Surface Plots in Creating 3-D Graphs in the Using MATLAB Graphics documentation
The following table summarizes the object properties that control transparency.
Transparency data for image and surface objects
Transparency data mapping method
Transparency of the faces (patch and surface only)
Transparency of the edges (patch and surface only)
Patch only alpha data property
Alpha axis limits
Alpha axis limits mode
There are three functions that simplify the process of setting alpha properties.
Set or query transparency properties for objects in current axes
Specify the figure alphamap
Set or query the axes alpha limits
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) p.FaceColor = 'red'; p.EdgeColor = 'none'; view(3) camlight left
Adding transparency to the isosurface reveals that there is greater complexity in the fluid flow than is visible using the opaque surface. The statement
sets the FaceAlpha value for the isosurface face to .5.
For images, the statement
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.