Plotting GNUPlot graph after computation

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.

Best Answer

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.

Related Topic