GNUPlot为什么不绘制与数据集中的点拟合的趋势线?

时间:2019-06-13 17:57:52

标签: gnuplot

我有以下GNUPlot命令序列:

$ cat bb.gnuplot
set datafile separator ","
set autoscale x
set autoscale y
set xdata time
set timefmt "%Y%m%d"
set format x "%Y%m%d"
set key left top
set grid
m=1
b=1
f(x) = m*x + b
fit f(x) "bb" using 1:2 via m,b
plot "bb" using 1:2 title "filebeat-6.5.1", f(x) title "fit"

附带此示例数据:

$ cat bb
20190416,0
20190417,0
20190418,0
20190419,0
20190420,0
20190423,0
20190424,0
20190425,0
20190426,0
20190509,0
20190510,72
20190511,62
20190512,63
20190513,108
20190514,78
20190515,66
20190516,59
20190517,86
20190518,57
20190519,57
20190520,62
20190521,78
20190522,95
20190523,104
20190524,22
20190525,128
20190526,96
20190527,125
20190528,129
20190529,152
20190530,160
20190531,148
20190601,136
20190602,178
20190603,198
20190604,148
20190605,140
20190606,142
20190607,171
20190608,205
20190609,174
20190610,198
20190611,208
20190612,205
20190613,13

我正试图让GNUPlot在同一图上绘制一条趋势线,但就它在我的图上的放置位置而言,我得到的线对我来说没有任何意义。

$  gnuplot < bb.gnuplot
iter      chisq       delta/lim  lambda   m             b
   0 1.0926745428e+20   0.00e+00  1.10e+09    1.000000e+00   1.000000e+00
   1 1.3194958855e+16  -8.28e+08  1.10e+08    1.098907e-02   1.000000e+00
   2 1.6307478323e+08  -8.09e+12  1.10e+07    1.279057e-06   1.000000e+00
   3 2.1025098835e+05  -7.75e+07  1.10e+06    5.819285e-08   1.000000e+00
   4 2.1025098815e+05  -9.56e-05  1.10e+05    5.819150e-08   1.000000e+00
iter      chisq       delta/lim  lambda   m             b

After 4 iterations the fit converged.
final sum of squares of residuals : 210251
rel. change during last iteration : -9.56318e-10

degrees of freedom    (FIT_NDF)                        : 43
rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 69.9254
variance of residuals (reduced chisquare) = WSSR/ndf   : 4889.56

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
m               = 5.81915e-08      +/- 7.064e-06    (1.214e+04%)
b               = 1                +/- 1.101e+04    (1.101e+06%)

correlation matrix of the fit parameters:
                m      b
m               1.000
b              -1.000  1.000

结果图:

enter image description here

我希望这条线能切穿我的点,并向我展示提供的数据点中的最佳拟合线。

我在这里想念什么?

1 个答案:

答案 0 :(得分:2)

我在手册中找不到合适的部分,我无法很好地解释它,但是 与您交换功能:

f(x) = m*(x-strptime("%Y%m%d","20190509")) + b

我想这与偏移量/预缩放有关,因为时间/日期数据在内部是从1970年1月1日起经过的秒数。因此,今天,2019年6月13日大约是。 1'560'000'000秒。而且您的时间跨度仅约为4'580'000秒,这使得很难找到合适的参数。如果我找到更好的解释,我会添加它(或者也许其他人可以解释得更好)。

结果:

enter image description here