In the development version 6.0, a new 'if (<expression>)' filter has been introduced for plot commands. This filter allows a data point to be skipped if the condition evaluates to false.</expression>
However, I have noticed that even when a data point is skipped by the 'if' filter, the 'xticlabels()' (or 'yticlabels()') in 'using' spec are still evaluated and their results are used. This leads to tic labels being added for data points that are not actually plotted.
I believe it would improve the usability of the 'if' filter if the processing of xticlabels() (and similarly yticlabels()) could also be skipped for rows that do not satisfy the condition.
I would greatly appreciate it if you could consider this enhancement.
Sample script:
$data <<EOD
0
1
2
3
4
5
6
7
8
9
10
11
12
EOD
set margins sc 0.2, sc 0.8, sc 0.2, sc 0.8
set key tmargin center offset 0,-2
plot $data using 1:1:xtic(1):ytic(1) with linespoints pt 7 if (int($1)%3 == 0)
pause -1
plot $data using 1:(int($1)%3 == 0?$1:NaN):xtic(1):ytic(1) with linespoints pt 7
pause -1
plot $data using (int($1)%3 == 0?$1:NaN):1:xtic(1):ytic(1) with linespoints pt 7
pause -1
plot $data using (int($1)%3 == 0?$1:NaN):(int($1)%3 == 0?$1:NaN):xtic(1):ytic(1) with linespoints pt 7
pause -1
plot $data using 1:1:xtic(int($1)%3 == 0?strcol(1):NaN):ytic(int($1)%3 == 0?strcol(1):NaN) with linespoints pt 7
pause -1
I agree with you that would make sense from the user's point of view.
Unfortunately I don't immediately see how to make that happen given the way the program is structured. The elements of the
using
specification are evaluated and applied as the data is read in (datafile.c). This includesxticlabel
. Theif
filter is applied only after the data is passed back to plot2d.c or plot3d.c, but by that time any side effects of evaluating theusing
specification have already happened, including the creation of a tic label ifxticlabel
was part of the specification.A similar problem would arise in cases like this:
You might think that this would set ymax to the maximum of only the points that were plotted, but since it is calculated before any filters are applied it will unexpectedly also include the y values of points that were later rejected.
This behavior is correctly described by the first sentence of the documentation for filters. Perhaps that should be expanded to explicitly mention that filters can only accept or reject individual data points, not undo side effects that resulted from reading in the data.