gnuplot - 如何使用 Gnuplot 4.6 在我的图表中追踪趋势线?

标签 gnuplot linear-regression curve-fitting

我有这些数据:

2019-08-28,384
2019-08-29,394
2019-08-30,406
2019-08-31,424
2019-09-01,439
2019-09-02,454
2019-09-03,484

还有 gnuplot 脚本:

set title "test"
set terminal png truecolor size 960,720 background rgb "#eff1f0"
set output "/home/tbenedet/Desktop/GNUPLOT\ AIX/test.png"
set grid
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5
set offsets 0.5,0.5,0,0.5
set datafile separator ","
plot "df_output.txt" using 2:xtic(1) with linespoints linestyle 1

我想画一条这样的趋势线:

enter image description here

但我的数学很差,我不知道如何使用 gnuplot 来做到这一点......有人可以告诉我吗?

最佳答案

假设您的数据由一条直线描述,您可以使用定义这样的方程并使用fit 命令。

set title "test"
set terminal pngcairo size 700,600
set output "test.png"
set grid
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5
set offsets 0.5,0.5,0,0.5
set datafile separator ","
set key Left left reverse

# The equation
f(x) = a*x + b
# The fit 
fit f(x) "df_output.txt" u 0:2 via a,b

set xtics rotate by 45 right

plot \
    "df_output.txt" u 2:xtic(1) w p ls -1 pt 7 title "data points",\
    f(x) w l lc "red" title "trendline"

结果

fit

关于gnuplot - 如何使用 Gnuplot 4.6 在我的图表中追踪趋势线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57806677/

相关文章:

python - 即使我迭代地改变初始猜测,scipy curve_fit 也不会收敛

gnuplot - xzplane中的网格

以分类状态作为阶跃函数的 gnuplot 时间序列

python - 无法将性别数据更改为二进制值

python - 出现错误 : Reshape your data either using array

R 有没有办法在线性回归中进行阈值处理?

c++ - 隐藏 C++ Gnuplot 管道控制台输出

GNUPLOT:带绘图和调色板的对数颜色框

python - 如何快速对多个数据集执行最小二乘拟合?

r - 改进 R 中数据的曲线拟合