13

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.

2 Answers 2

18

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Could you also tell me if I want to multiply a certain column by say 5, what will be the command?
@Swaranga Sarma Edited the answer to include an example. I used 2 instead of 5, to emphasize that column numbers and literals can be used together without problem.
5

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.