Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
This operation is commonly known as "scaling", maybe that word merits to be in the title? – Dmitry Grigoryev Jun 2 '15 at 15:06
up vote 12 down vote accepted

Supposing 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, than you can operate on the values in the following way:

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'. Instead, if you prefer to rewrite the data file, you can do it automatically through 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.

share|improve this answer
+1 in either case. – Rook Feb 13 '10 at 13:17
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. – Asa Oct 3 '14 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .