Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the start of the x-axis at 1 instead of 0

Tags:

gnuplot

I use gnuplot to plot execution times measured on the CPU and GPU depending on the data size. So I have two files with the execution times in it. Plotting them is straight forward.

set title "CPU vs GPU"

set xlabel "Number of Particles (* 10'000)"
set ylabel "Time in Microseconds"

plot "cpuTimes.txt" title "CPU" with linespoints, \
     "gpuTimes.txt" title "GPU" wit

The resulting plot can be found here: 1

I tried to use xtics however it doesn't shift the x-axis to start at 1 but just starts the ticks at 1. How can I shift the x-axis so it starts at 1 and ends at 50?

Update

Datafile cpuTimes.txt below

64780
129664
195490
266697
327871
391777
459150
517999
582959
647984
717377
790415
830869
900475
959599
1026041
1092899
1156022
1297471
1286325
1349227
1415936
1482857
1539580
1607389
1673436
1737098
1801568
1874431
1935975
2006892
2053077
2129867
2195117
2254467
2314478
2373546
2435416
2506850
2587302
2625556
2674799
2758387
2820720
2896794
2953550
3053817
3089501
3170513
3271537
like image 802
Nils Avatar asked Jul 13 '11 13:07

Nils


2 Answers

xtics are only to "label" the x-axis. What you are looking for is some sort of "data manipulation". I'd suggest making use of using like so:

plot "cpuTimes.txt" u ($0+1):1 t "CPU" w lp, \
     "gpuTimes.txt" u ($0+1):1 t "GPU" w lp

To make the plot end at 50 there are two ways:

  1. You could specify the x-range with set xrange [1:50] or with

    plot [1:50] "cpuTimes.txt" u ($0+1):1 t "CPU" w lp, \
                "gpuTimes.txt" u ($0+1):1 t "GPU" w lp
    
  2. You need to include every like so:

    plot "cpuTimes.txt" u ($0+1):1 every 1::::50 t "CPU" w lp, \
         "gpuTimes.txt" u ($0+1):1 every 1::::50 t "GPU" w lp
    

    See every for documentation for further reference.

like image 102
Woltan Avatar answered Oct 31 '22 18:10

Woltan


I haven't used gnuplot in awhile, but I believe you can use set xrange to adjust what is plotted.

In your case the command is:

set xrange [ 1 : 50 ]
like image 38
Tom Hazel Avatar answered Oct 31 '22 18:10

Tom Hazel