gnuplot: skip missing columns
An answer to this question on Stack Overflow.
Question
I plot something like (gnuplot 4.6rc1):
plot "data1.csv" using "time":"value_a", \
"data2.csv" using "time":"value_b", \
"data3.csv" using "time":"value_c"
Having csv files like:
time, value_a, value_c
0, 1, 2
4, 5, 6
If one column is missing (say value_b) the whole plot will not be produced with error could not find column with header "value_b".
Is there a way to just skip plotting this column, instead of skipping the whole plot?
Answer
You can use the following data file:
time, value_a, value_c, value_b
0, 1, 2
4, 5, 6
Notice that the value_b column has a header, but it does not require any data points. GNUplot will find the column and be happy, but since there is no data it will not be plotted. Since header generation only occurs once per output file it is hopefully easy enough to add all the column names.
I don't know of a solution which allow you to omit the column entirely. But... another way to plot your data is with:
plot "data1.csv" using "time":"value_a"
replot "data2.csv" using "time":"value_b"
replot "data3.csv" using "time":"value_c"
So if you can keep track of which columns you are printing out, then you can build the plot file in this way.
And, if that isn't possible, then your problem is now reduced to getting GNUplot to continue to the next line if there's an error. Sadly, I'm not sure how to make it do that.