Patch - controlling transition of transparency - how to?
조회 수: 2 (최근 30일)
이전 댓글 표시
I made a plot where the patch background goes from a specific color to full transparency (not white color).
Question is: I would like to change the transparency limits and don't know how. You can see that for some peaks the blue color goes from deep blue to full transparency. Some of them don't, and I don't like that. I want every peak to have a transition from full blue to full transparency. Or better - precisely control it from-to. How to do it please?
I'm stuck on the FaceVertexAlphaData property and have no idea exactly what to put in it and how.
Working code snippet for all blue peaks:
% fit(:,1) is for X data, fit(:,i) is for Y data; data are in a columns
for i = 2:9
patch(fit(:,1),fit(:,i),'b','edgecolor','none','FaceAlpha','interp','FaceVertexAlphaData',fit(:,i)); % background
plot(fit(:,1),fit(:,i),'Color','b'); % edges
end
댓글 수: 0
채택된 답변
Voss
2023년 3월 8일
To have all patches span the full transparency range, use normalized values, where each column of fit is normalized separately.
% some matrix, I call it fitt (fit is a built-in function)
x = (71:169).';
fitt = [x 100*exp(-(x-110).^2/10) 50*exp(-(x-135).^2/30) 20*exp(-(x-95).^2/60)];
% normalize each column of fitt by dividing by its maximum
fitt_norm = fitt./max(fitt,[],1);
figure
hold on
% fitt(:,1) is for X data, fitt(:,i) is for Y data; data are in a columns
for i = 2:size(fitt,2)
patch(fitt(:,1),fitt(:,i),'b', ...
'edgecolor','none', ...
'FaceAlpha','interp', ...
'FaceVertexAlphaData',fitt_norm(:,i)); % background
plot(fitt(:,1),fitt(:,i),'Color','b'); % edges
end
댓글 수: 5
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!