Jenny B
Jenny B

Reputation: 209

Basic 2-dimensional graph with gnuplot

I have the followint txt file:

# tlb_size  AMAT    tlb_miss_rate
2   2918.67 19.85
4   2905.33 13.20
8   2900.00 10.50
16  2892.33 6.60
32  2884.33 2.71
64  2881.00 0.93
128 2880.00 0.56
256 2879.67 0.41
512 2879.67 0.36
1024    2879.67 0.33
2048    2879.67 0.27
4096    2879.67 0.27

I want to plot 2 curves on one 2-dimensional graph: of AMAT as a function of tlb_size and the second curve tlb_miss_rate as a function of (also) tlb_size. The x-asis being the tlb_size, the y-axis being AMAT and tlb_size, hopefully for some normal scale.

It is very basic but I can't find the solution. Please help.

Upvotes: 1

Views: 1084

Answers (1)

Soz
Soz

Reputation: 963

To simply plot column 1 as x axis, with AMAT and tlb_size on column 2, you can do:

gnuplot> plot "test.txt" using 1:2, "" using 1:3

However, that doesn't look particularly readable, so you could set the y axis to a log scale (note: "" is shorthand for 'the same file I already mentioned'):

gnuplot> set log y 
gnuplot> plot "test.txt" using 1:2, "" using 1:3
gnuplot> plot "test.txt" using 1:2 with lines, "" using 1:3 with lines

If you don't want to use that log scale, you could try defining two independent y axes. Don't forget to unset log y first, or it'll still plot on a log scale for one of the lines:

set ytics axis
set y2tics 
plot "test.txt" using 1:2 with lines, ""  using 1:3 axes x1y2 with lines

Incidentally, it has been pointed out to me that your data looks particularly good if you use a log2 scale for the x axis:

set logscale x 2 
plot "test.txt" using 1:2 with lines, ""  using 1:3 axes x1y2 with lines

Comes out looking like this:

Sample

Upvotes: 4

Related Questions