【问题标题】:How to trace a trendline in my graph with Gnuplot 4.6?如何使用 Gnuplot 4.6 在我的图表中跟踪趋势线?
【发布时间】:2019-09-05 13:32:29
【问题描述】:

我有这些数据:

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

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

但我的数学很差,我不知道如何用 gnuplot 做到这一点……有人给我看吗?

【问题讨论】:

    标签: gnuplot linear-regression curve-fitting


    【解决方案1】:

    假设您的数据用直线描述,您可以使用定义这样的方程并使用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"
    

    结果

    【讨论】:

    • 您好,谢谢您的回答!很有帮助 !我知道如何用一条曲线做到这一点,但如果我有这些日期(pastebin.com/K9e3Aa57)和这个 gnuplot 脚本(pastebin.com/0XEJvz6V),我会创建两条曲线,一条用于可用空间,另一条用于以 mb 为单位的总容量...如何为第一条和第二条曲线创建趋势线?
    • 您可以定义两个直线方程并执行两个拟合或在每个拟合命令之后将参数保存到另一个变量。但是,total capacity 数据是不变的。 free space 数据不连续。因此,对于最后一个,直线并不是数据拟合的最佳模型。
    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多