1

I have two files 'results.dat' and 'grid.dat'.

The results.dat contains per row a different data set of y values.

1     325.5   875.4   658.7   365.5
2     587.5   987.5   478.6   658.5
3     987.1   542.6   986.2   458.7

The grid.dat contains the corresponding x values.

1     100.0   200.0   300.0   400.0

How can I plot with gnuplot the grid.dat as x values und a specific line of results.dat as corresponding y values? E.g. line 3:

1     100.0   987.1
2     200.0   542.6
3     300.0   986.2
4     400.0   458.7

Thanks in advance.

Sebastian
  • 755
  • 3
  • 7
  • 22

1 Answers1

0

Thats quite similar to the recent question Gnuplot: plotting the maximum of two files. In your case it is also not possible to do it with gnuplot only.

You need an external tool to combine the two files on-the-fly, e.g. with the following python script (any other tool would also do):

""" selectrow.py: Select a row from 'results.dat' and merge with 'grid.dat'."""
import numpy as np
import sys

line = int(sys.argv[1])       

A = np.loadtxt('grid.dat')
B = np.loadtxt('results.dat', skiprows=(line-1))[0]

np.savetxt(sys.stdout, np.c_[A, B], delimiter='\t')

And then plot the third line of results.dat with

plot '< python selectrow.py 3' w l
Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187