2

Lets say I have a data file with three columns. I want to be able to change the x-axis labels. After a little googling I found xticlabels() but the problem is that it only seems to take a column number as the argument. For ex- plotting with xticlabels(3) marks the labels with the third column.

I want to be able to put something like $1+$2 as the argument for this function i.e. the label should be a concatenation of column1 and column2.

How do I do this ?

Neal
  • 3,119
  • 4
  • 27
  • 32

1 Answers1

4

You use awk...

plot "<awk '{print $1,$2,$1 $2}' datafile" u 1:2:xticlabels(3) 

Of course, this is a silly example because we're concatenating 2 (numeric) fields to create the labels -- It's doubtful that is what you want, but it shows how to concatenate two fields (as strings) in awk and that's really all you need.

Alternatively, you can probably coax gnuplot to do this (untested) with some variant of the following:

plot 'datafile' u 1:2:( xticlabels( stringcolumn(1).stringcolumn(2) ) )
mgilson
  • 300,191
  • 65
  • 633
  • 696
  • stringcolumn() works and it is what I was looking for. btw the example is not very silly as the data file may contain string fields as well and not only numerics. thank you :) – Neal May 29 '12 at 20:29
  • I'm glad to know the second solution worked (and a little surprised) -- things don't usually work out well if they're not tested ;). – mgilson May 29 '12 at 23:50