Gnuplot:数据归一化 [英] Gnuplot: data normalization
问题描述
我有几个规模非常不同的基于时间的数据集,例如g.
I have several time-based datasets which are of very different scale, e. g.
[set 1]
2010-01-01 10
2010-02-01 12
2010-03-01 13
2010-04-01 19
…
[set 2]
2010-01-01 920
2010-02-01 997
2010-03-01 1010
2010-04-01 1043
…
自2010年1月1日以来,我想绘制两者的相对增长情况.要将两条曲线放在同一张图上,我必须对其进行归一化.因此,我基本上需要选择第一个Y值并将其用作权重:
I'd like to plot the relative growth of both since 2010-01-01. To put both curves on the same graph I have to normalize them. So I basically need to pick the first Y value and use it as a weight:
plot "./set1" using 1:($2/10), "./set2" using 1:($2/920)
但是我想自动执行此操作,而不是硬编码10和920作为分隔符.我什至不需要第二列的最大值,我只想选择第一个值,或者最好是给定日期的值.
But I want to do it automatically instead of hard-coding 10 and 920 as dividers. I don't even need the max value of the second column, I just want to pick the first value or, better, a value for a given date.
所以我的问题是:有没有一种方法可以对给定列的值进行参数化,该值对应于给定X列的给定值(X是时间轴)?像
So my question: is there a way to parametrize the value of a given column which corresponds a given value of the given X column (X is a time axis)? Something like
plot "./set1" using 1:($2/$2($1="2010-01-01")), "./set2" using 1:($2/$2($1="2010-01-01"))
其中$ 2($ 1 ="2010-01-01")是我要的功能.
where $2($1="2010-01-01") is the feature I'm looking for.
推荐答案
选择第一个值非常容易.只需记住它的值并用它除以所有数据值即可:
Picking the first value is quite easy. Simply remember its value and divide all data values by it:
ref = 0
plot "./set1" using 1:(ref = ($0 == 0 ? $2 : ref), $2/ref),\
"./set2" using 1:(ref = ($0 == 0 ? $2 : ref), $2/ref)
更需要使用给定日期的值:
Using the value at a given date is more involved:
使用外部工具(awk)
ref1 = system('awk ''$1 == "2010-01-01" { print $2; exit; }'' set1')
ref2 = system('awk ''$1 == "2010-01-01" { print $2; exit; }'' set1')
plot "./set1" using 1:($2/ref1), "./set1" using 1:($2/ref2)
使用gnuplot
您可以使用gnuplot的 stats
命令选择所需的值,但是您必须注意在此之后进行所有时间设置:
You can use gnuplot's stats
command to pick the desired value, but you must pay attention to do all time settings only after that:
a)字符串比较
stats "./set1" using (strcol(1) eq "2010-01-01" ? $2 : 1/0)
ref1 = STATS_max
...
set timefmt ...
set xdata time
...
plot ...
b)比较实际时间值(仅从版本5.0开始如此工作):
b) Compare the actual time value (works like this only since version 5.0):
reftime = strptime("%Y-%m-%d", "2010-01-01")
stats "./set1" using (timecolumn(1, "%Y-%m-%d") == reftime ? $2 : 1/0)
ref1 = STATS_max
...
set timefmt ...
set xdata time
...
plot ...
这篇关于Gnuplot:数据归一化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!