Transparent lines

7 messages
Open this post in threaded view
|

Transparent lines

 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 MWEfigure()t=linspace(0,2*pi,10000);hold onp1=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 offI would like to have the plot lines with some sort of translucency. In Matlab, I can then putp1.Color(4)=0.05to set the alpha channel to 5%Octave resultMatlab result (with 5% transparency for p1...p4)I just want to plot high frequency signals, and present the noise as a shadow of the filtered signal. Thanks-------------------------Félix Salazar[hidden email]-------------------------
Open this post in threaded view
|

Re: Transparent lines

 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.htmlBut 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 ``s you'd like to be transparent. HTH, Markus
Open this post in threaded view
|

Re: Transparent lines

 > I was wondering if there would be any way to plot lines with > transparency, or to set an alpha channel in the color spec for a plot You can use the FaceAplha property for patch and surface objects.  So instead of a line you can create a patch which has the shape of the line you need. -- Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058 ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107 via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti (gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it
Open this post in threaded view
|

Re: Transparent lines

 Administrator In reply to this post by mmuetzel > 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%playing with this a bit myself, i was wondering what changed in p1.  it's an odd hack. checking the properties of p1 before changing Color(4):>> get(p1)    AlignVertexCenters: off            Annotation: [1×1 matlab.graphics.eventdata.Annotation]          BeingDeleted: off            BusyAction: 'queue'         ButtonDownFcn: ''              Children: [0×0 GraphicsPlaceholder]              Clipping: on                 Color: [0 0.4470 0.7410]             ColorMode: 'auto'           ContextMenu: [0×0 GraphicsPlaceholder]             CreateFcn: ''       DataTipTemplate: [1×1 matlab.graphics.datatip.DataTipTemplate]             DeleteFcn: ''           DisplayName: ''      HandleVisibility: 'on'               HitTest: on         Interruptible: on              LineJoin: 'round'             LineStyle: '-'         LineStyleMode: 'auto'             LineWidth: 0.5000                Marker: 'none'       MarkerEdgeColor: 'auto'       MarkerFaceColor: 'none'         MarkerIndices: [1×10000 uint64]            MarkerMode: 'auto'            MarkerSize: 6                Parent: [1×1 Axes]         PickableParts: 'visible'              Selected: off    SelectionHighlight: on           SeriesIndex: 1                   Tag: ''                  Type: 'line'              UserData: []               Visible: on                 XData: [1×10000 double]             XDataMode: 'manual'           XDataSource: ''                 YData: [1×10000 double]           YDataSource: ''                 ZData: [1×0 double]           ZDataSource: ''>> p1.Colorans =         0    0.4470    0.7410then >> p1.Color(4) = 0.05 definitely changes the plot, but the object properties are unchanged:>> p1.Color(4)=.05p1 =   Line with properties:              Color: [0 0.4470 0.7410]          LineStyle: '-'          LineWidth: 0.5000             Marker: 'none'         MarkerSize: 6    MarkerFaceColor: 'none'              XData: [1×10000 double]              YData: [1×10000 double]              ZData: [1×0 double]Show all properties    AlignVertexCenters: off            Annotation: [1×1 matlab.graphics.eventdata.Annotation]          BeingDeleted: off            BusyAction: 'queue'         ButtonDownFcn: ''              Children: [0×0 GraphicsPlaceholder]              Clipping: on                 Color: [0 0.4470 0.7410]             ColorMode: 'manual'           ContextMenu: [0×0 GraphicsPlaceholder]             CreateFcn: ''       DataTipTemplate: [1×1 matlab.graphics.datatip.DataTipTemplate]             DeleteFcn: ''           DisplayName: ''      HandleVisibility: 'on'               HitTest: on         Interruptible: on              LineJoin: 'round'             LineStyle: '-'         LineStyleMode: 'auto'             LineWidth: 0.5000                Marker: 'none'       MarkerEdgeColor: 'auto'       MarkerFaceColor: 'none'         MarkerIndices: [1×10000 uint64]            MarkerMode: 'auto'            MarkerSize: 6                Parent: [1×1 Axes]         PickableParts: 'visible'              Selected: off    SelectionHighlight: on           SeriesIndex: 1                   Tag: ''                  Type: 'line'              UserData: []               Visible: on                 XData: [1×10000 double]             XDataMode: 'manual'           XDataSource: ''                 YData: [1×10000 double]           YDataSource: ''                 ZData: [1×0 double]           ZDataSource: ''and checking on the transparency: >> p1.Color(4)Index exceeds the number of array elements (3).>> p1.Color(4) = 0.01(changes image fine, same behavior)I'm guessing they added some hack to catch the element 4 assignment and perform the transparency change without actually making it a 4 element color assignment. Odds are a similar 'catch the deviant assignment' hack would work if we had a way to apply transparency in our graphics toolkits.
Open this post in threaded view
|

Re: Transparent lines

 Administrator In reply to this post by Francesco Potortì You can use the FaceAplha property for patch and surface objects.  So instead of a line you can create a patch which has the shape of the line you need.would that eventually run into scaling issues?