How do you change the transparency of multiple lines using "plot" if the lines are all different colors?
Afficher commentaires plus anciens
Im trying to plot 15 lines in a single graph. Each line is a different color and would like all of them to be semi-transparent (alpha =0.2). Alpha does not work and when I use the 'Color' [value value value 0.2] it changes all the lines to the same color.
Réponses (1)
Les Beckham
le 28 Sep 2022
Modifié(e) : Les Beckham
le 28 Sep 2022
h = plot(rand(5)); % example plot. When you make your plot be sure to capture the handle
% now set the alpha on all the lines in the plot handle h
for i=1:numel(h)
c = get(h(i), 'Color');
set(h(i), 'Color', [c 0.2]);
end
grid on
3 commentaires
Ales Holeta
le 4 Mai 2023
Hello, I'm working in LiveScripts and the transparency feature doesn't work in it. it's super stupid..
v R2022b
Les Beckham
le 4 Mai 2023
Interesting. You're right, it doesn't work in a Live Script.
I would report that as a bug. Scroll down to the bottom of this page and click the "Contact Support" link under the Get Support heading.
Walter Roberson
le 4 Mai 2023
the ability to add transparency to line objects is undocumented, and has some notable restrictions:
- does not work for Livescript
- transparency is not saved if you save to a .fig
- an implication of the above is that transparency of this kind is not saved if you pass graphic objects to or from parallel workers or background pools.
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
