2

I would like to draw a kind of PivotChart using Gnuplot. So I need to ignore some lines of data in my file. I tried the following:

unset key

set xtics font "Times-Roman, 5" 
set ytics font "Times-Roman, 5" 

set multiplot layout 4,3 #title "Multiplots\n"

plot [7:50][0:1] 'forStackoverGnuplot.txt' using 1:($2==0?($3==4?$4:NaN):NaN) with lines ti '4'
plot [7:50][0:1] 'forStackoverGnuplot.txt' using 1:($2==0?($3==4?$4:"fe"):"fe") with lines ti '4'

Datafile:

20  0   5   0.668593155
7   0   4   0.885223087
20  0   5   0.668593155
10  0   4   0.92239289
20  0   5   0.668593155
20  0   4   0.834947746
30  0   4   0.693726036
50  0   4   0.47169919

But I get: Bad charts

which is not the result I expected. What can I do? I want to let the data lines interlaced.

Ranumao
  • 413
  • 4
  • 17

1 Answers1

5

Basically, gnuplot differentiates between missing and invalid data points, see e.g. In gnuplot, with “set datafile missing”, how to ignore both “nan” and “-nan”?.

If you have an undefined point (e.g. as NaN or 1/0), the plot line is interrupted. To achieve this, you would need to set datafile missing. But that doesn't work if you evaluate something in the using statement, because then its too late for the 'undefined' <-> 'missing' choice (Selecting columns e.g. with using 1:4 is ok). So the statement

set datafile missing '?'
plot 'forStackoverGnuplot.txt' using 1:(($2==0 && $3==4) ? $4 : '?')

does not work.

Instead you must filter the data externally, and remove the affected rows, before plotting them:

unset key
set style data linespoints

set multiplot layout 1,2 

plot [7:50][0:1] 'forStackoverGnuplot.txt' using 1:(($2==0 && $3==4) ? $4 : 1/0)

filter = '< awk ''{ if ($2 == 0 && $3 == 4) print $1, $2, $3, $4}'' '
plot [7:50][0:1] filter.' forStackoverGnuplot.txt' using 1:4

unset multiplot

This gives:

enter image description here

In the left graph the points are plotted, but are not connected by lines, because there are 'invalid' points between them.

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187