Search code examples
gnuplot

Gnuplot: plot every N points in range including the interval edges


I have some data files with around 10k records; each record containing a value plus the standard deviation for it.

I'm plotting the standard deviation as a slightly transparent filledcurve. However, since there were some weird artifacts with painting so many points, I've resorted to using the every command to plot every 99 points.

'$1' using 1:(\$3-\$5):(\$3+\$5) every 99::0 with filledcurves ls $COUNTER notitle

This works perfectly; however my problem is that depending on how many exact records I have in the file, the every command may skip the last entries, which ends up with the colored standard deviation area ending before its respective line.

Missing std

Is there any way to include the last record to the every command/filled plot so that the colored area extends to where it needs to?

EDIT: The effect I'm trying to avoid is this:

flickery plot

I can't seem to really reproduce it atm as I'm working with new data, but I'm sure that picking points every once in a while avoids it.


Solution

  • [amended to show full treatment of NaN value. Demo'ed with a real data file]

    Instead of every, you can construct a filter function for the using specifier.

    set xrange [100:600]
    xmax = 600
    filter(x) = (int(column(0))%9 == 0  ||  x == xmax) ? 1 : 0
    set datafile missing NaN
    plot 'silver.dat' using (filter($1)?$1:NaN) : ($2-$3) : ($2+$3) with filledcurves, \
         '' using 1:2 with lines
    

    enter image description here