14

I want to add an offset to the data from a file which i want to plot using gnuplot. Suppose i want to add an offset of 0.001 to all the data values from file before i plot them . How can i do it in gnuplot without having to rewrite the data file with the offsets.

Thanks.

2 Answers 2

21

Try something like this:

plot "Data.dat" u ($1):($2 + 0.001) w l

The $1 and $2 specify the column you want to plot. Simply add a constant like 0.001 to the column or even add two columns like so: $1 + $2.

I hope that answers your quastion
Cherio Woltan

Sign up to request clarification or add additional context in comments.

2 Comments

To clarify how to add offset to X column when not specifying X column: Note that "$0 or column(0) returns the sequence number of this data record within a dataset." When you are plotting and just specifying the y-coord (e.g. 'plot "datafile" using 2 with lines') then you are implicitly using the column(0). That plot command is the same as 'plot "datafile" using 0:2 with lines'. To add an X-offset and/or Y-offset you can change it like this: 'plot "datafile" using ($0+17):($2+42) with lines'.
I have to say the whole shortcut syntax, especially in examples, makes it ever harder to read - was it really that much effort to write with lines instead of w l and using instead of u? gnuplot should really do away with the whole abbreviated syntax altogether. It does not serve anybody except perhaps spare the script interpreter some CPU time.
3

I think it is better to let gnuplot compute offset, instead of guessing the right constant...

off(x) = sin(x) + offset
fit off(x) "data" using 1:2 via offset
plot off(x)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.