How can I set the transparency of LINE objects in MATLAB 7.14 (R2012a)?
Show older comments
I would like to set the transparency of LINE objects in my figures. I use the ALPHA command to set the transparency of objects in my figure. However, LINE objects do not respect ALPHA values even though I am using the OPENGL renderer.
Accepted Answer
More Answers (1)
Fabian
on 31 Jul 2015
you could try setting a four-element vector for the color property of the line. works for me in 2014 b.
lh.Color=[0,0,0,0.5]
with lh handle to the line, producing a black line with transparency 0.5
7 Comments
Walter Roberson
on 31 Jul 2015
Interesting. This does not appear to be documented.
(I do not have R2014b or later so I cannot test.)
TheStranger
on 1 Sep 2017
Srry for the offtop, but any ideas why it was not put in the help? Looks like an easter egg, lol. I think someone should write a book like "MATLAB a bunch of undocumented stuff", because it is not the first time I encounter some problem, which can be solved, but the solution isn't in the help menu :)
Walter Roberson
on 1 Sep 2017
Edited: MathWorks Support Team
on 15 Jul 2025
You might be interested in: https://undocumentedmatlab.com/
DGM
on 3 Aug 2022
@Troy Skousen's comment-as-answer moved here:
I'm using R2021b. It looks like it will not take a 4 element color any more. Any other thoughts?
DGM
on 3 Aug 2022
I can't test anything beyond R2019b, but undocumented features are subject to change without notice; after all, if there's no documentation, the changes aren't documented either.
The 4-element colour vector seems to work in R2022a —
x = 0:0.01:2*pi;
y = sin(x);
figure
plot(x, y, '-', 'Color',[0.2 0.5 0.9 0.8], 'LineWidth',2.5) % Alpha = 0.8
hold on
plot(x, y+0.25, '-', 'Color',[0.2 0.5 0.9 0.2], 'LineWidth',2.5) % Alpha = 0.2
hold off
.
Walter Roberson
on 15 Jul 2025
The 4-element colour vector continues to work in R2025a.
However, anything that causes the line object to be copied or regenerated with lose the alpha information, including:
- copyobj
- saving and loading the plot or portions of the plot
- sending the plot between parallel workers and the client
- resizing the axes
- print() or exportobj() (both of which cause the figure to be copied to a temporary figure, then internal properties are adjusted to fit the page size and resolution properties in effect, then the modified version is rendered.)
Categories
Find more on Display Image in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!