2
votes

I have a file with two columns, the first containing purely real numbers and the second containing complex number in a form the GNUPLOT will accept, {a,b} (which is GNUPLOT's equivalent to a + bi). I would like to plot the first column with the absolute value of the second so I tried this:

plot 'data.dat' using 1:abs(2)

This, however, doesn't seem to work. Does anyone know how I can tell GNUPLOT to perform an operation on the data in the dat file before plotting it?

3

3 Answers

3
votes

It would save yourself a lot of effort and store your data in three columns, where the second and third denote real and imaginary part.

You can achieve what you are looking for by:

plot "data" using 1:(sqrt($2**2+$3**2))
3
votes

The complex form {a,b} only accepts constants for a and b, to use the abs function you have to use

plot 'data.dat' using 1:(abs($2+$3*{0,1}))
1
votes

it seems by default it just reads your complex number as a string..try this:

plot 'data.dat' using 1:(sqrt($2**2+$3**2)) '%lf { %lf , %lf }'

I could not figure a way to use the built in abs however..this doesnt work for some reason:

plot 'data.dat' using 1:(abs({$2,$3})) '%lf { %lf , %lf }'