问题描述
我有一些数据(k-selection
算法的基准测试结果)具有不规则的x值.我将它们明确标记(1、50、100、500、1000、2500和5000).
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).
由于这些值不是线性增加的(或指数增加的,尽管使x轴成为对数刻度确实可以改善某些情况,错误在1到50之间留下了巨大的缺口),它们奇怪地散布在一起了.有没有一种方法可以缩放x轴,以便以均匀的间距绘制这些数据点?
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?
以下是网格间距的示例(eps文件中不显示标签和图例,它们稍后由graphicx软件包绘制)以及我正在使用的gnuplot命令.
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'
推荐答案
最干净的方法是使用xticlabels
命令:
The cleanest way to do it is to use the xticlabels
command:
plot '../data/selection.dat' u ($2/1000):xticlabels(1) t 'Sort', \...
这将从第一列中获取值并将其用作x轴标签,而将第二列用作数据.
This takes the value from the first column and uses it as the x axis labels, while using the second column as data.
这有点像使用命令
plot 'file' u 2
这只是根据伪索引(1,2,3,4 ...)绘制第二列的数据.这样可以给数据点提供均匀的间距,这似乎就是您想要的.
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.
这篇关于不规则的gnuplot x值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!