Patch - controlling transition of transparency - how to?

3 visualizaciones (últimos 30 días)
Leo
Leo el 8 de Mzo. de 2023
Comentada: Leo el 9 de Mzo. de 2023
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

Respuesta aceptada

Voss
Voss el 8 de Mzo. de 2023
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 comentarios
Voss
Voss el 9 de Mzo. de 2023
You're welcome!
Out of curiosity, what's the problem in R2023a prerelease?
Leo
Leo el 9 de Mzo. de 2023
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by