Irregular gnuplot x-values

泪湿孤枕 提交于 2019-12-11 03:14:13

问题


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.

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'

回答1:


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.



来源:https://stackoverflow.com/questions/13507565/irregular-gnuplot-x-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!