efritz
efritz

Reputation: 5203

Irregular gnuplot x-values

I have some data (benchmarking results of k-selection algorithms) which has irregular x-values. I have them labeled explicitly (1, 50, 100, 500, 1000, 2500, and 5000).

Because these values are not linearly increasing (or exponentially increasing, although making the x-axis a logscale does improve things a bit, bug leaves a huge gap in between 1 and 50) they are oddly spread out and clumped together. Is there a way to scale the x-axis so that these data points are drawn at an even spacing?

Below is a sample of the grid spacing (labels and legends are not visible in the eps file, these are drawn later by the graphicx package) as well as the gnuplot commands I'm using.

grid spacing

set terminal epslatex

set xlabel 'k'
set ylabel 'seconds'

set tic scale 0
set key Left outside

set xtics rotate
set xtics ('1' 1, '50' 50, '100' 100, '500' 500, '1000' 1000, '2500' 2500, '5000' 5000)

set logscale y
set logscale x
set style data linespoints

set output 'selection.tex'

plot '../data/selection.dat' u 1:($2/1000) t 'Sort', \
     '../data/selection.dat' u 1:($3/1000) t 'Partial Sort', \
     '../data/selection.dat' u 1:($4/1000) t 'Heap', \
     '../data/selection.dat' u 1:($5/1000) t 'Partial Heap', \
     '../data/selection.dat' u 1:($6/1000) t 'Order Statistics'

Upvotes: 4

Views: 1200

Answers (1)

andyras
andyras

Reputation: 15910

The cleanest way to do it is to use the xticlabels command:

plot '../data/selection.dat' u ($2/1000):xticlabels(1) t 'Sort', \...

This takes the value from the first column and uses it as the x axis labels, while using the second column as data.

This is a bit like using the command

plot 'file' u 2

Which just plots the data from the second column against a dummy index (1,2,3,4...). This gives an even spacing to the data points, which seems to be what you want here.

Upvotes: 3

Related Questions