Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting GNUPlot graph after computation

Tags:

gnuplot

I have a data file that lists hits and misses for a certain cache system. Following is the data file format

time hits misses
1 12 2
2 34 8
3 67 13
...

To plot a 2D graph in GNUPlot for time vs hits, the command would be:

plot "data.dat" using 1:2 using lines

Now I want to plot a graph of time vs hit-ratio, For this can I do some computation for the second column like :

plot "data.dat" using 1:2/ (2 + 3) using lines

Here 1, 2, 3 represent the column number.

Any reference to these kind of graph plotting will also be appreciated.

Thanks in advance.

like image 791
Swaranga Sarma Avatar asked Jun 08 '11 08:06

Swaranga Sarma


2 Answers

What you have is almost correct. You need to use $ symbols to indicate the column in the calculation:

plot "data.dat" using 1:($2/($2 + $3))

Since you are using $n to refer to the column numbers, you now are able to use n to refer to the number itself. For example,

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

will double the value in the second column.

like image 148
Michael J. Barber Avatar answered Oct 03 '22 11:10

Michael J. Barber


In general, you can even plot C functions like log and cos of a given column. For example:

plot "data.dat" u 1:(exp($2))

Note the parens on the outside of the argument that uses the value of a particular column.

See here for more info.

like image 35
Dan Avatar answered Oct 03 '22 13:10

Dan