【发布时间】:2019-05-02 16:23:06
【问题描述】:
拥有不一定按日期排序的日期和事件列表 例如喜欢
# Date Event
04.12.2018 -4
23.06.2018 5
04.10.2018 3
11.11.2018 -9
08.03.2018 -4
08.03.2018 2
11.11.2018 -3
我想总结事件并进行(例如线性)外推,例如当数据达到某个阈值(例如零)时。
看起来smooth frequency 和smooth cumulative 似乎是为此而生的。
但我正在努力解决以下问题:
a) 如何添加起始值(偏移量),例如StartValue = 500
plot $Data u (strftime("%d.%m.%Y",timecolumn(1,"%d.%m.%Y"))):($2+StartValue) smooth cumulative w l t "Cumulated Events"
不这样做。
b) 如何获取累积数据?特别是如果数据不是按日期排序的?
set table "DataCumulative.dat"
plot $Data u (strftime("%d.%m.%Y",timecolumn(1,"%d.%m.%Y"))):2 smooth cumulative with table
unset table
这看起来类似于这个问题 (GNUPLOT: saving data from smooth cumulative),但我没有得到预期的数字。在我下面的文件"DataCumulative.dat" 的示例中,我期望唯一的日期,基本上是来自下图中的数据。这个怎么弄?
代码:
### start code
reset session
set colorsequence classic
# function for creating a random date between two dates
t(date_str) = strptime("%d.%m.%Y", date_str)
date_random(d0,d1) = strftime("%d.%m.%Y",rand(0)*(t(d1)-t(d0)) + t(d0))
# create some random date data
date_start = "01.01.2018"
date_end = "30.06.2018"
set print $Data
do for [i=1:1000] {
print sprintf("%s\t%g", date_random(date_start,date_end), floor(rand(0)*10-6))
}
set print
set xdata time
set timefmt "%d.%m.%Y"
set xtics format "%b"
set xrange[date_start:"31.12.2018"]
set multiplot layout 2,1
plot $Data u (strftime("%d.%m.%Y",timecolumn(1,"%d.%m.%Y"))):2 smooth frequency with impulses t "Events"
plot $Data u (strftime("%d.%m.%Y",timecolumn(1,"%d.%m.%Y"))):2 smooth cumulative w l t "Cumulated Events"
unset multiplot
# attempt to get cumulative data into datablock
set table "DataCumulative.dat"
plot $Data u (strftime("%d.%m.%Y",timecolumn(1,"%d.%m.%Y"))):2 smooth cumulative with table
unset table
### end of code
【问题讨论】:
标签: gnuplot smoothing cumulative-sum