Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doing calculations in gnuplot's plot command

Tags:

gnuplot

The following gnuplot code works good:

plot 'data.txt'  using 2:4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;

In the following code, I want to say: "Use the number from column 4, but then divide it by the number from column 3". Or: "Use the number from column 2, but divide it by the constant 2.0". The following code demonstrates what I try to achieve, but it does not work.

plot 'data.txt'  using 2:4/4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;
plot 'data.txt'  using 2:4/2.0  '   %lf %lf %lf %lf' title "1 PE" with linespoints;

Is something like this possible?

like image 352
Johannes Avatar asked Feb 20 '13 10:02

Johannes


People also ask

How do you write exponents in gnuplot?

Gnuplot uses two asterisks for exponentiation. Thus plot x**2+8*x+15 produces a quadratic with x-intercepts at -3 and -5. Gnuplot helpfully reminds one of what is being graphed in the upper right corner. Commands can be issued in a sequence to modify the graph appearance.

Can user defined functions be created in gnuplot?

User-Defined FunctionsIf you can write an equation, gnuplot can calculate it. I mean, functions to be plotted are expressed in a simple functional form, for example, f(x)=a*x+b, and they do not contain a complicated integration / differentiation which needs a numerical calculation.

How do I use gnuplot?

Running gnuplot is easy: from a command prompt on any system, type gnuplot. It is even possible to do this over a telnet or ssh connection, and preview the graphs in text mode! For best results, however, you should run gnuplot from within X Window, so that you can see better previews of your plots.

How use gnuplot command in Linux?

To run GNUPlot, you simply open a terminal, type “gnuplot” and hit enter. This will launch the software tool so you are ready to set your variables and start plotting.


1 Answers

I don't usually work with datafiles formatted like this, but I think you're looking for something like:

#divide column 4 by column 3
plot 'data.txt'  using 2:($4/$3)  '   %lf %lf %lf %lf' title "1 PE" with linespoints

#divide column 4 by constant 10.0
plot 'data.txt'  using 2:($4/10.0)  '   %lf %lf %lf %lf' title "1 PE" with linespoints

As a side note, I don't think there's any reason for passing the format portion to using here. Gnuplot splits the datafile on whitespace just fine:

plot 'data.txt'  using 2:($4/$3) title "1 PE" with linespoints

Should work just fine.

like image 161
mgilson Avatar answered Oct 13 '22 19:10

mgilson