How do you change the transparency of multiple lines using "plot" if the lines are all different colors?

14 views (last 30 days)
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.

Answers (1)

Les Beckham
Les Beckham on 28 Sep 2022
Edited: Les Beckham on 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

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by