3

How can I plot a function of data with xmgrace?

Let's say I have a 3-columns file and I want to plot the sum of 2nd and 3rd column as a function of the 1st. With gnuplot, I can just do

p "file.dat" u 1:($2+$3)

How can I do the same thing with xmgrace?

valerio
  • 677
  • 4
  • 12
  • 25

2 Answers2

2
awk '{print $1, ($2 + $3)}' file.dat | xmgrace -pipe &

Example: Plot data for y = x^2 + 4

Contents of file.dat:

0 0 4
1 1 4
2 4 4
3 9 4
4 16 4
5 25 4
6 36 4

Output (after modifying styles):

Plot of y = x^2 + 4

feedMe
  • 3,431
  • 2
  • 36
  • 61
2

A pure grace solution would be to create a batch file (say myplot.batch) that reads

READ BLOCK "file.dat"
BLOCK xy "1:2" 
BLOCK xy "1:3" 
s0.y=s0.y-s1.y 
KILL s1      

And execute using

xmgrace -batch myplot.batch
h k
  • 320
  • 2
  • 13