Search code examples
plotgraphgnuplotrgbcolor

Gnuplot plot every nth line a specific colour


I have a graph with several lines on it, read in from different columns in a data file. I'd like each of the lines to be black, then every fifth line be red. I've managed to get every fifth line be not-black but can't figure out how to specify red using the gnuplot rgbcolor variable syntax.Here is my current attempt

The line is use to specify these colours is:

plot for [i=2:max_col] 'data_file.txt' u 1:i:((i-1)%5==0?(255000000):0) w l lc rgbcolor variable lw 2.8

My question is, what do I place in the condition so that the line colour is red? I'm using gnuplot 4.6 so the 255<<16 trick to get red produces an error.


Solution

  • Either use hex notation:

    plot for [i=2:max_col] 'data_file.txt' u 1:i:((i-1)%5==0?0xff0000:0) w l lc rgbcolor variable
    

    Or define two linetypes or styles between which you switch with lc variable:

    set linetype 1 lc 'black'
    set linetype 2 lc 'red'
    plot for [i=2:max_col] 'data_file.txt' u 1:i:((i-1)%5==0? 2 : 1) w l lc variable