Swaranga Sarma
Swaranga Sarma

Reputation: 13413

Plotting GNUPlot graph after computation

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.

Upvotes: 13

Views: 16713

Answers (2)

Dan
Dan

Reputation: 12675

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.

Upvotes: 5

Michael J. Barber
Michael J. Barber

Reputation: 25042

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.

Upvotes: 18

Related Questions