Re: Transparent lines

Markus Mützel <[email protected]>
Newsgroups gmane.comp.gnu.octave.general
Message-ID <trinity-8f1070a0-3f23-4f43-8300-1e4ef3b6476e-1615824139053@3c-app-gmx-bs71>
Am 15. März 2021 um 15:30 Uhr schrieb "Felix Salazar":
> Hello community,
> 
> I was wondering if there would be any way to plot lines with tranasèarency, or to set an alpha channel in the color spec for a plot. Or at least plans to implement it in the future.
> 
> a MWE
> 
> figure()
> t=linspace(0,2*pi,10000);
> hold on
> p1=plot(t,sin(t)+0.25*randn(size(t)));
> p2=plot(t,sin(t+pi/2)+0.25*randn(size(t)));
> p3=plot(t,sin(t-pi/2)+0.25*randn(size(t)));
> p4=plot(t,sin(t+pi)+0.25*randn(size(t)));
> hold off
> 
> I would like to have the plot lines with some sort of translucency. In Matlab, I can then put
> p1.Color(4)=0.05
> to set the alpha channel to 5%
>
> I just want to plot high frequency signals, and present the noise as a shadow of the filtered signal.
 
I wasn't aware that it was possible to pass the alpha channel as part of the color property. It seems to be undocumented afaics:
https://de.mathworks.com/help/matlab/ref/matlab.graphics.primitive.line-properties.html

But I can see where that feature can be useful. Thanks for pointing this out.

Getting transparency right is tricky. In particular, there is currently no code in Octave that could do the necessary back-to-front sorting to render 3d scenes with transparency correctly.
Nonetheless, having transparent lines in a 2d scene that is similar to the one you showed is probably possible without complicated back-to-front sorting -- if the user could print the transparent lines from the background before printing any solid lines in the foreground.

Currently, Octave doesn't accept RGBA quadruplets as values for the "color" property of lines.  Nor does it have other means to plot lines with transparency.

Since this would be a new feature, it won't be added before the next major release.

In the meantime: If you *really* need transparent lines, you could save the figure as a .svg file and add `stroke-opacity="0.05"` to the `<polyline>`s you'd like to be transparent.

HTH,
Markus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.