How do I draw transparent lines in MATLAB R2011a (7.12)?
1 view (last 30 days)
Show older comments
I want to plot transparent lines (as opposed to surfaces or patches).
Accepted Answer
MathWorks Support Team
on 5 Jun 2013
Currently, MATLAB line objects don't have a transparency property and thus can't be made transparent. In other words, commands such as PLOT can't create transparent lines.
A workaround involves using the PATCH function to draw a patch that looks like a line and setting the "EdgeAlpha" property.
x = [0 10 20 50 60];
y = [0 5 10 5 0];
xflip = [x(1 : end - 1) fliplr(x)];
yflip = [y(1 : end - 1) fliplr(y)];
patch(xflip, yflip, 'r', 'EdgeAlpha', 0.1, 'FaceColor', 'none');
The "EdgeAlpha" property value determines the transparency of the line. Make sure to set "FaceColor" to "none" as the PATCH function may produce unexpected behavior when collapsed into a line (fill the entire axes with the fill color).
Note that transparency is possible due to the use of the OpenGL renderer. Changing the renderer, or doing any operation that results in the same, will remove the transparency. For example, setting the axis from linear to log will change the renderer to ZBuffer. To re-set the transparency features change the renderer back to OpenGL with the following command:
set(gcf,'renderer','opengl');
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!