将数据集值读入gnuplot变量(X系列的开始) [英] Reading dataset value into a gnuplot variable (start of X series)

查看:102
本文介绍了将数据集值读入gnuplot变量(X系列的开始)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初认为这可能与 gnuplot-X系列的开始-堆栈溢出-但我认为这是更具体的.

I originally thought this may be the same as gnuplot - start of X series - Stack Overflow - but I think this is slightly more specific.

由于我有兴趣寻找"X系列的开始",所以可以这么说-我将尝试举例说明;说你有这个脚本:

Since I'm interested in finding the "start of X series", so to speak - I'll try to clarify with an example; say you have this script:

# generate data
system "cat > ./inline.dat <<EOF\n\
10.0 1 a 2\n\
10.2 2 b 2\n\
10.4 3 a 2\n\
10.6 4 b 2\n\
10.8 5 c 7\n\
11.0 5 c 7\n\
EOF\n"

# ranges 
set yrange [0:8]
set xrange [0:11.5]

plot "inline.dat" using 1:2 with impulses linewidth 2

如果进行绘制,您会注意到数据在x轴上从10开始:

If you plot it, you'll notice the data starts from 10 on x-axis:

现在,您当然可以调整xrange了-有时您可能会对以从0开始"的相对位置"感兴趣.因此,人们希望看到数据在x轴上向左移动",因此它从0开始.由于我们知道数据从10.0开始,因此我们可以从第一列中明确减去它:

Now, of course you can adjust the xrange - but sometimes you're interested in "relative positions" which start "from 0", so to speak. Therefore, one would like to see the data "moved left" on the x-axis, so it starts at 0. Since we know the data starts at 10.0, we could subtract that from first column explicitly:

plot "inline.dat" using ($1-10.0):2 with impulses linewidth 2

...基本上可以解决问题.

... and that basically does the trick.

但是说您不要想要在上面的plot命令中显式指定"10.0";然后-知道这是已经加载的数据的第一列的第一个元素,因此希望有一种方法可以某种方式读取变量中的该值-例如,使用类似以下伪代码的内容:

But say you don't want to specify the "10.0" explicitly in the plot command above; then - knowing that it is the first element of the first column of the data which is already loaded, one would hope there is a way to somehow read this value in a variable - say, with something like the following pseudocode:

varval = "inline.dat"(1,1) # get first element of first column in variable
plot "inline.dat" using ($1-varval):2 with impulses linewidth 2

...就像这样,可以不必在plot命令中手动指定此"x offset"值.

... and with something like this, one wouldn't have to specify this "x offset" value, so to speak, manually in the plot command.

那么-换个说法-是否有一种方法可以读取x系列的开头(数据集中给定列的第一个值)作为gnuplot中的变量?

So - to rephrase - is there a way to read the start of x series (the first value of a given column in a dataset) as a variable in gnuplot?

推荐答案

两种方式:

1. 首先绘制函数,然后让gnuplot告知最小x值:

1. Plot the function first and let gnuplot to tell the minimum x value:

plot "inline.dat" using 1:2 with impulses linewidth 2

xmin = GPVAL_DATA_X_MIN
plot "inline.dat" using ($1-xmin):2 with impulses linewidth 2

2. 使用外部脚本找出最小x值是什么:

2. Use external script to figure out what is the minimum x value:

xmin = `sort -nk 1 inline.dat | head -n 1 | awk '{print $1}'`
plot "inline.dat" using ($1-xmin):2 with impulses linewidth 2

这篇关于将数据集值读入gnuplot变量(X系列的开始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆