我想,我现在终于明白了。然而,有几点我仍然不完全理解。
1.
为了获得累积数据,不应设置
set table $DataCumulative
plot $Data u (stringcolumn(1)):2 smooth cumulative with table
unset table
但是:
set table $DataCumulative
plot $Data u (stringcolumn(1)):2 smooth cumulative
unset table
请注意缺少的“
with table
2.
默认的数据文件分隔符设置
那是
set datafile separator whitespace
它似乎不起作用。它将给出一条错误消息,如
line xxx: No data to fit
相反,你必须设置
set datafile separator " \t" # space and TAB
但我不明白为什么。
拟合时间日期
f_lin(x) = m*x + c
f_lin(x) = m*(x-strptime("%d.%m.%Y", Date_Start)) + c
我记得很久以前在gnuplot文档中读过这篇文章,但是我再也找不到了。
目前,我对以下几点感到高兴。
修改后的代码:
reset session
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))
Date_Start = "01.01.2018"
Date_End = "30.06.2018"
set print $Data
do for [i=1:100] {
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 "%d.%m.%Y"
set table $DataCumulative
plot $Data u (stringcolumn(1)):2 smooth cumulative
unset table
set xtics format "%b"
set datafile separator " \t"
f_lin(x) = m*(x-strptime("%d.%m.%Y", Date_Start)) + c
set fit nolog quiet
fit f_lin(x) $DataCumulative u 1:2 via m,c
Level_Start = 500
Level_End = 0
x0 = (Level_End - Level_Start - c)/m + strptime("%d.%m.%Y", Date_Start)
set multiplot layout 3,1
set xrange[Date_Start:"31.12.2018"]
set xtics format ""
set lmargin 7
set bmargin 0
plot $Data u (timecolumn(1,"%d.%m.%Y")):2 smooth frequency with impulses lc rgb "red" t "Events 2018"
set xtics format "%b"
set bmargin
plot $Data u (timecolumn(1,"%d.%m.%Y")):2 smooth cumulative w l lc rgb "web-green" t "Cumulated Events 2018"
set label 1 at x0, graph 0.8 strftime("%d.%m.%Y",x0) center
set arrow 1 from x0, graph 0.7 to x0, Level_End
set key at graph 0.30, graph 0.55
set xrange[Date_Start:x0+3600*24*50]
set xtics format "%m.%y"
set yrange [-90:]
plot $DataCumulative u (timecolumn(1,"%d.%m.%Y")):($2+Level_Start) w l lc rgb "blue" t "Cumulated Events",\
Level_End w l lc rgb "red" not,\
f_lin(x)+Level_Start w l ls 0 t "Fitting \\& Extrapolation"
unset multiplot
将导致: