13

I want to write a bash script to automate the plotting of data, using a plotting tool called xmgrace, but I want to be able to select which columns are plotted.

Say in my data file I have 3 columns, with the x and y data in the 1st and 3rd columns. How do I plot x against y when the data is formatted this way?

I tried xmgrace -bxy [1:3] data but that didn't work, it said No block data read and treated the second column as the y values.

Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
Eddy
  • 6,661
  • 21
  • 58
  • 71

2 Answers2

19

The correct syntax for this kind of problem is

xmgrace -block file -bxy 1:3 

This will

  1. Read the file as a block file
  2. Plot the 3rd column against the 1st column.
abarnert
  • 354,177
  • 51
  • 601
  • 671
Daniel
  • 206
  • 2
  • 3
  • 2
    FYI, `-bxy 0:3` plots the 3rd column vs the row number. – Jorge Leitao Apr 09 '15 at 14:16
  • Also, for set types involving more than two columns, such as xydy (x,y and errorbars), the syntax is `xmgrace -block file -settype xydy -bxy 1:2:3`. – h k Jul 18 '17 at 15:19
4

Another flexible way of accomplishing the same thing is to use awk or cut:

awk '{print $1,$3}' data | xmgrace -
cut -f1,3 data | xmgrace -
mstringer
  • 2,242
  • 3
  • 25
  • 36