I would like to plot a file like the following:
this is some header
that is written by the measurement software
for example it contains the date: 2018/1/1
column 1 column 2 column 3 column 4
1 12 13 13 14
2 15 15 15 15
3 10 12 13 15
4 9 9 8 8
5 7 9 10 11
6 6 6 6 6
So there is a multi-line header separated to the data by a blank line. Well easy enough just use the every command I thought. But there are some Problems (MWE):
reset
$testdata << EOD
this is some header
that is written by the measurement software
for example it contains the date: 2018/1/1
column 1 column 2 column 3 column 4
1 12 13 13 14
2 15 15 15 15
3 10 12 13 15
4 9 9 8 8
5 7 9 10 11
6 6 6 6 6
EOD
# set datafile separator "\t"
# set key autotitle columnhead
# set datafile commentschars "abcdefghijklmnopqrstuvwxyz"
# errors: bad data on line X:
# plot $testdata
# plot $testdata every ::1
# plot $testdata every ::2
# plot $testdata every ::3
plot $testdata every ::4
If I plot just the file without every I get a bad data error (as expected). My understanding is that I need to ignore the first 4 lines because they are just text and hence have to use plot $testdata every ::4, but this also ignores the first 3 data points and the plot starts at x=4.
Using every ::3 is possible, the plot then starts at x=3.
Using every ::1 or every ::2 yields a bad data error again.
If I uncomment set key autotitle columnhead the title just changes to "is" or "this is some Header" (depending on datafile separator), so the head is not ignored at all. Also while now every ::2 works (..and the plot starts at x=2), every ::1 still yields the error.
My goal is to get a plot that includes every datapoint obviously + using the columnheaders as title. My current workaround is set datafile commentschars "abcdefghijklmnopqrstuvwxyz", but this prevents me from using the columnhead-titles. Is there a gnuplot-only way to handle this? I can NOT change the file formatting as it is the output of a measurement device. Also, I am aware of tools like awk, but I'm not the admin and cannot install Software. This should also be avoided to allow running the script on different machines.
Any help is greatly appreciated! Thanks a lot
Data filtering with every is done only after the whole data was parsed. That's why you get warning and errors, because the first line cannot be parsed correctly.
To skip some line before the actual parsing starts, use the skip keyword:
$testdata <<EOD
this is some header
that is written by the measurement software
for example it contains the date: 2018/1/1
"column 1" "column 2" "column 3" "column 4"
1 12 13 13 14
2 15 15 15 15
3 10 12 13 15
4 9 9 8 8
5 7 9 10 11
6 6 6 6 6
EOD
set key autotitle columnheader
plot $testdata skip 4 using 1:2 w lp

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With