Search code examples
gnuplot

if condition in gnuplot for the third axis


I want to make a plot of a file in palette format,

plot 'file.dat' u ($3-$10):($196-$203):($196=$203) pointtype 1 lc palette,\
     'file.dat' u ($7-$14):($200-$207):($200=$207) pointtype 1 lc palette

Whereas the choice of the columns is not regular, I need to use an if condition for the palette axis (bar) which indicates that if column $196=$203 plot column $196 or if $200=$207 plot $200.

I don't know whether this is possible in gnuplot or I should skip using gnuplot.


Solution

  • From your description I still don't get your point. That's what I've understood so far. You take some operation of some columns to determine the x- and y-coordinates (in your case: $3-$10 and $196-$203). And now, you want to determine the color of the datapoint by what? By some condition? What is the condition? So, what color do you want if the condition is met ($196==$203) and what color do you want to have if the condition is not met (i.e. $196!=$203).

    I order to get any further, I made a minimal example with data and with graph. If the value in column 3 is equal to the value in column 4 the color of the datapoint will be according to the palette using column 3, and NaN (= not plotted) otherwise. Is this coming close to what you want to achieve? Maybe we can go on from this...

    Code:

    ### conditional plotting
    reset session
    
    $Data <<EOD
    1   21  1  0
    2   22  2  2
    3   23  3  0
    4   24  4  4
    5   25  5  0
    6   26  6  6
    7   27  7  0
    EOD
    
    set palette rgb 33,13,10
    
    plot $Data u ($1+$2):($3+$4):($3==$4 ? $4 : NaN) w p pt 7 ps 3 lc palette notitle
    ### end of code
    

    Result:

    enter image description here