How can I display a surface plot with semi transparent plane segmenting the data in MATLAB 71.13 (R2011b) ?

36 views (last 30 days)
I plot my surface data using the SURF command. I would like to display a plane parallel to the XY plane so I can visually observe the data segmented. I would also like this plane to be partly transparent.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Jul 2013
A plane in a MATLAB Figure can be created using a PATCH object. This can be overlaid over the surface plot and certain properties of the patch changed to make it transparent.
The following steps describe the process. The sample code is at the end.
1) Assuming that you would like the patch to span the X-Y plane displayed, we first obtain the limits of the X an Y axes and used these to mark the (X,Y) co-ordinates of the four corners of the patch.
figure;
% Sample data created
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
mesh(Z);
hold on;
% Z threshold value.
threshold = .5; % please change this as needed .
% Obtain the limits of the axes
yp = get(gca,'Ylim');
xp = get(gca,'Xlim');
% Use the axes x and Y limits to find the co-ordinates for the patch
x1 = [ xp(1) xp(2) xp(2) xp(1)];
y1 = [ yp(1) yp(1) yp(2) yp(2)];
2) Since the patch is parallel to the XY plane, the Z co-ordinate for the 4 points is equal to the threshold.
z1 = ones(1,numel(x1))* threshold; % creates a 1x4 vector representing the Z coordinate values
3) Create a patch using these values for X,Y and Z co-ordinates and pass the color of the patch as the 4th argument.
p = patch(x1,y1,z1, 'b');
4) By default, the patch is solid. To add transparency to the surface of the patch, we set the 'facealpha' property to a number between 0 and 1. This leaves the edges solid. To make them transparent, set the 'edgealpha' property.
% Set the Face and edge transparency to 0.2 using the following properties
set(p,'facealpha',0.2)
set(p,'edgealpha',0.2)

More Answers (0)

Products


Release

R2011b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!