25

I have column-formatted data and I want to make a splot of the logarithm of the 5th column versus the first two columns. I have tried:

set pm3d map
splot "thing.file" u 1:2:log($5)

But I get the error

undefined value

How can I get gnuplot to plot a function of one of the columns of data?

Dan
  • 12,157
  • 12
  • 50
  • 84

3 Answers3

36

This works:

splot "thing.file" u 1:2:(log($5)) 

In general, if a term is defined by a function of a column in a data file rather than the column itself, there need to be parentheses around that term.

Dan
  • 12,157
  • 12
  • 50
  • 84
6

To extend the solution, you can use multiple columns if your function requires multiple inputs: example:

plot "file" using 1:(x=$2, y=$3, f(x,y)) 

also works.

hanitors
  • 143
  • 1
  • 3
  • A note to noobs like me. In gnu plot, while writing a function, one doesn't write x^y but x**y. I was making this mistake. – Prem Jan 10 '21 at 10:09
-7

Taken from gnuplot's own FAQ , "Gnuplot has been and is a plotting program,not a data processing or mathematical program suite. Therefore gnuplot can't do that.".

You can run your data file through Octave or Matlab to generate the log files before plotting.

LTK
  • 1
  • 4
    Figured it out: If I enter: splot "thing.file" u 1:2:(log($5)) it runs the function on that column. In general, there need to be parentheses around an expression involving functions of a column, I think. – Dan Jun 08 '11 at 23:24
  • 2
    @Dan Why not make that an answer? – Mateen Ulhaq Jun 09 '11 at 00:49
  • I don't have enough reputation to answer my own question until 8 hours after I post it. – Dan Jun 09 '11 at 02:38