11

I have gnuplot data file. I would like to plot it, but divide every value in the x-axis by n.

Can I do this from within gnuplot, or do I have to rewrite the data file?

1
  • This operation is commonly known as "scaling", maybe that word merits to be in the title? Jun 2, 2015 at 15:06

1 Answer 1

24

Assuming that the x values are in the first column of the file 'test.dat' and the y values are in the second column of the same file, then you can write:

plot 'test.dat' using ($1/n):($2)

See the manual for more information and examples on the 'using' keyword.

Note that this will not change the values of your data file 'test.dat'. If you prefer to rewrite the data file, you can do it using awk. For example:

awk '{print $1/n,$2}' test.dat > testnew.dat

will substitute the x values in the first column of test.dat with x/n and will generate a new file called testnew.dat.

2
  • Submitted an edit to fix a broken link to the last HTML version of the manual. Also note that the manuals are only available as PDF in recent versions. gnuplot.info/documentation.html
    – Asahiko
    Oct 3, 2014 at 20:50
  • We can even divide the values of certain columns: plot "path/to/data.dat" using 1:($5/$3) with lines
    – Dohn Joe
    Dec 5, 2018 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.