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

采纳的回答

Voss
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 个评论
Voss
Voss 2023-3-9
You're welcome!
Out of curiosity, what's the problem in R2023a prerelease?
Leo
Leo 2023-3-9
Well there were two issues - you solved the first one (transparency limits).
Second was a different thing. Since I'm switching between versions, the last image I posted is actually from the R2023a version (I got them confused). As you can see the patch just wasn't created for some peaks and instead I got the aforementioned warning (also from R2023a). I honestly have no idea what it means. It will probably be reproducible in R2023a with my last mentioned script (and also yours).
In 2022b there's no such a thing. Everything runs smoothly.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by