2

I want to use the plot command in gnuplot with expression evaluation, i.e.

plot "-" using ($1):($2) with lines
1 10
2 20
3 ?
4 40
5 50
e

But I want it to ignore the missing data "?" in such a way that it connects the line (and doesn't break it between 2 and 4).
I tried set datafile missing "?", but in agreement with the online-help it does not connect the lines. The following would, but I cannot use expression evaluation:

plot "-" using 1:2 with lines
1 10
2 20
3 ?
4 40
5 50
e

Any ideas how to connect the lines and use expression evaluation?

Woltan
  • 13,723
  • 15
  • 78
  • 104
highsciguy
  • 2,569
  • 3
  • 34
  • 59
  • Can you describe a little more what you want? Are you talking about using math expression minus, or reading from stdin (special filename "-")? Some more real sample data would be helpful. – vaettchen Sep 30 '11 at 05:23
  • The special file "-" is just used in the online-help example. It could be any datafile in gnuplot format for 2-d plots. Just put the two columns in a file named "data.dat" and translate the commands into plot "data.dat" using ($1):($2) with lines, or "data.dat" using 1:2 with lines. Expression evaluation means that I want e.g. plot "data.dat" using ($1):($2/$1) with lines, which makes sense only if the brackets are present. – highsciguy Sep 30 '11 at 23:16

1 Answers1

2

Two column data

If you set up a data file Data.csv

1 10
2 20
3 ?
4 40
5 50

you can plot your data with connected lines using

plot '<grep -v "?" Data.csv' u ($1):($2) w lp

More than two column data

For more than two columns you can make use of awk.
With a data file Data.csv

1 10 1
2 20 2
3 ?  3
4 40 ?
5 50 5

you can run a script over the data file for each plot like so:

plot "<awk '{if($2 != \"?\") print}' Data.csv" u ($1):($2) w lp, \
     "<awk '{if($3 != \"?\") print}' Data.csv" u ($1):($3) w lp

A reference on scripting in gnuplot can be found here. The awk user manual here.

Woltan
  • 13,723
  • 15
  • 78
  • 104
  • Yes, but this does not work (in the required way) if I have a three column data file, where the third column has correct data in the third line which I do want to use. Admittedly the two-column example given above is too simplistic for that. But if I have just two columns there are of course plenty of ways to remove the unknown data. – highsciguy Sep 30 '11 at 23:18