3

I have some measured data, experiment.dat which goes like this:

1 2
2 3

Now I want to plot them via some command line

plot "experiment.dat" using 1:2 title "experiment" with lines lw 3

Is there some way how to scale the different lines with some scaling factor like -1?

2 Answers 2

5

Yes, you can do any kind of calculations inside the using statement. To scale the y-value (the second column) with -1, use

plot "experiment.dat" using 1:(-1*$2)
1

You don't need to multiply the column by minus one, you can simply use:

p "experiment.dat" u 1:(-$2)

at least with Version 5.4 works fine.

You can also only use the initial letter of every command.

2
  • 1
    This answer could be improved by explaining what you changed and why.
    – Sean
    Oct 8, 2020 at 0:13
  • 1
    just to mention: using 1:(-$2) will work for gnuplot 4.4 (March 2010) and also for gnuplot 5.2.8 (Dec 2019). But using 1:($-2) will not work for gnuplot <=5.2.8. I cannot test 5.4.
    – theozh
    Oct 9, 2020 at 15:59

Your Answer

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

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