Search code examples
pythongnuplotcolor-mapping

How to make a transparent plotted point


Here I am trying to achieve a radar effect on the spider/radar plot. Ideally I would like to have the plotted line dissapear given I time (for example over in 30 seconds the plotted line fades to transparent, I was thinking changing like sequential colormap or the plotted line is deleted/cleared) but that may cause issues. So if the plotted line transition/fade to transparent would allow less clutter on the overall plot. It is possible but tricky for me..

set grid ls 10

set xtics axis format "" scale 0
set ytics axis format ""

set size square

set style line 9 lt 1 lw 2 pt 2 ps 2

set multiplot layout 1,2

plot 'somedata' using 1:5 t "" w lp ls 9
unset multiplot

pause 90
replot

How can I acheive this in Gnuplot? In my reading I came accross something called Lerp/ Lerping colors, however I am not using Csharp or Unity.

output showing markers that need to fade/clear. The main difference is that there would be just 1 not 9 as piture

example of points that need to transition/fade to transparent


Solution

  • From your descriptions it still not clear to me what your expectations are. So, here is an example of what I would consider a "radar effect", i.e. fading away the colors. It's setting transparent colors in a while loop (check help while) which you can stop by pressing x (check help bind). The code can certainly be further optimized, but I hope you can adapt it to your needs.

    Code:

    ### attempt to mimic a radar screen
    reset session
    
    # create some test landscape
    set xrange [-8:8]
    set yrange [-8:8]
    set samples 50 
    set isosamples 50
    set contour
    set cntrparam level 5
    set table $Data 
        splot (sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))*3
    unset table
    unset contour
    set angle degrees
    Angle(dx,dy) = dx==dx && dy==dy ? dx==0 ? dy==0 ? NaN : \
                   abs(sgn(dy))*180-sgn(dy)*90 : dx<0 ? 180+atan(dy/dx) : \
                   dy<0 ? atan(dy/dx)+360 : atan(dy/dx) : NaN
    r(x,y) = sqrt(x**2 + y**2)
    set table $Contour
        plot $Data u (Angle($1,$2)):(r($1,$2)) index 1::1 
    unset table
    
    set size ratio 1
    set polar
    unset border
    set border polar lc "green"
    unset xtics
    unset ytics
    set format r ""
    unset raxis
    set rtics scale 0
    set format t ""
    set grid lw 2 lc "green"
    set obj 1 rect from screen 0,0 to screen 1,1 fc "black" behind     # black background
    
    stop = 0
    bind x "stop=1"
    
    $Data <<EOD
    45    5
    0   4
    123   3.5
    325   3.5
    EOD
    
    unset key
    set trange [0:360]
    set rrange [0:8]
    
    alpha(a,a0)    = int((1-exp(-real(a)/a0))*255)<<24       # transparency "decay" 
    myBaseColor    = 0x00ff00
    myColorA(a)    = myBaseColor + alpha(a,45)               # decay for radar "beam"
    AngleDiff(a,b) = b>a ? b-a : 360-a+b
    myColorB(a,b)  = myBaseColor + alpha(AngleDiff(a,b),220) # decay for data
    
    a=90; step=5
    while (!stop) {
        a = a<step ? a=a+360-step : a-step
        do for [i=0:180] {
            set obj 100+i circle at 0,0 size 8 arc [a+i:a+i+2] fs solid noborder fc rgb myColorA(i) behind
        }
        plot $Data u 1:2:(myColorB(a,$1)) w p pt 7 lc rgb var, \
             $Contour u 1:2:(myColorB(a,$1)) w l lc rgb var
    }
    ### end of code
    

    Result: (screen capture taken with ScreenToGif from wxt terminal)

    enter image description here