Search code examples
colorsgnuplotfence-plots

Gnuplot: Alternating colors in fenceplots


I want to to plot a fenceplot with alternating fence colors. In this case I want black and grey. I used the following code:

splot for [i=0:300:25] "fenceplot.csv" index i u 1:2:3 w lines

The number of fences defined in my data file is dynamic and is usually between 250-350 fences.

Fence


Solution

  • Because the variable i changes by 25 between subsequent curves you can decide which color to use for a given line by testing whether i is even or odd:

    set style line 1 linecolor "black"
    set style line 2 linecolor "grey"
    splot for [i=0:300:25] "fenceplot.csv" index i u 1:2:3 w lines linestyle 1+i%2
    

    Slightly more robust would be

    splot for [i=0:12] "fenceplot.csv" index i*25 u 1:2:3 w lines linestyle 1+i%2
    

    because then you can also replace 25 by an even number.