1

In Gnuplot 5.2 you can use plot "datafile" ... title columnheader(1) to display the string in first in datafile as key. However when you try to append a string like in plot "datafile" ... title columnheader(1) . "X", it fails with unexpected ot unrecognized token.

However when I use plot "datafile" ... title columnhead(1) . "X" it works!

So what is the difference between columnheader(N) and columnhead(N), and why do both exist?

See also https://stackoverflow.com/a/36138352/6607497

U. Windl
  • 3,480
  • 26
  • 54

1 Answers1

1

The help text tries to explain this. columnhead(x) is a string-valued function. As such it can be composed or combined with other functions.

gnuplot> help columnhead
 `columnhead(x)` may only be used as part of a plot, splot, or stats command.
 It evaluates to a string containing the content of column x in the first line
 of a data file. See `plot datafile using`.

Note that this function can be used anywhere in the plot command, not just as a title option. For a contrived example:

plot DATA using 1:2:(columnhead(3)) with labels

By contrast the keyword columnheader is valid only as a title option. The common use is as an option to the set key command in the form

set key autotitle columnheader

where it would affect all plot components generated from data files (as opposed to functions). As a convenience it is also allowed as a title substitute for a single plot component, as in

plot DAT1 using 1 title "foo", DAT2 using 2 title "baz", DAT3 using 3 title columnheader

A drawback of this is that the program has to guess which column is meant. It is unambiguous in the example above, but consider:

   plot DAT3 using ($2+$3)/($4) title columnheader  # _which_ columnheader?

So as a special case the program looks to see if a particular column in parentheses immediately follows the keyword. I.e. it looks like a function but isn't really. The program could be smarter and realize that it could use the actual function columnhead(), but unfortunately it isn't that smart.

Ethan
  • 13,715
  • 2
  • 12
  • 21
  • So would you agree that any occurrence of `columnheader(N)` can be replaced with `columnhead(N)`? So it seems to me that `columnheader(N)` was superseded with `columnhead(N)`, but was left intact for compatibility. – U. Windl Jun 09 '20 at 12:44
  • Yes, at least for the current source. I'm not sure how many versions back this was true for. They are converging but not yet identical. I see now (24 hrs later) that I wrote "columnhead" in my answer in most of the places where I meant to write "columnheader", thus proving how confusing it is. Now corrected. – Ethan Jun 09 '20 at 15:58