FaceAlpha of surf plot takes the first row and column twice

조회 수: 2 (최근 30일)
Emiel
Emiel 2014년 3월 21일
댓글: Emiel 2014년 3월 23일
Hi all,
This problem has been bugging me for quite some time so I decided to post the question. When I'm trying to use face alpha on a surf plot to make some faces disappear, I found that the first row and column of the alphadata matrix are used for the first two rows. Example:
[X,Y] = meshgrid(1:5,1:5);
Z = ones(5,5);
A = zeros(5,5);
A(1,1) = 1;
surf(X,Y,Z,'FaceAlpha','flat','AlphaDataMapping','none','AlphaData',A)
I would expect this code to draw only the first face (1,1), but it draws faces (1,1), (2,1), (1,2) and (2,2). When I turn on index (2,2) of the alphadata it does show only one face, though shifted:
[X,Y] = meshgrid(1:5,1:5);
Z = ones(5,5);
A = zeros(5,5);
A(2,2) = 1;
surf(X,Y,Z,'FaceAlpha','flat','AlphaDataMapping','none','AlphaData',A)
Why can't I control the first two rows and columns separately? Is it a bug? The results of both codes are shown in the image below. Left is the first part and right the second:
Thanks in advance, Emiel

채택된 답변

Rob Comer
Rob Comer 2014년 3월 23일
This variation does what I think you're hoping for:
[X,Y] = meshgrid(1:5,1:5);
Z = ones(5,5);
C = ones(4,4);
A = zeros(4,4);
A(1,1) = 1;
surf(X,Y,Z,'CData',C,'AlphaData',A, ...
'FaceColor','texturemap','FaceAlpha','texturemap')
It sets the color and alpha data on each face instead of at each vertex (echoing Chad's concern), which goes along with the 'texturemap' settings.
  댓글 수: 1
Emiel
Emiel 2014년 3월 23일
Aha, thanks a lot! This is a nice work around. Still the original method doesn't behave as it says it does in the documentation, I'll report that. Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chad Greene
Chad Greene 2014년 3월 21일
Interesting. My question is, why would it make sense to define alpha at vertices? By that I mean, the alphadata is defined for intersections of lines, not the squares between the intersections. A simple workaround is to change facealpha to interp by plotting with this line:
surf(X,Y,Z,'FaceAlpha','interp','AlphaDataMapping','none','AlphaData',A)
But that doesn't explain the odd placement of the alpha map using the flat method.
  댓글 수: 1
Emiel
Emiel 2014년 3월 21일
Thanks for your answer. With the surf plot I represent a 2D FEM mesh. The displacements are indeed defined at the vertices but I have some other property defined on and constant over each element (face), represented by the alpha value. Therefore I want the whole face have some alpha value and not interpolate between the vertices.. I get the idea that this is a bug, but lets hope it's not.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by