【问题标题】:When using Gnuplot, how can the equation of a line be printed in the line title?使用 Gnuplot 时,如何在行标题中打印行的方程?
【发布时间】:2012-02-22 14:50:54
【问题描述】:

我使用 Gnuplot 绘制数据以及线性回归线。目前,这条线的“标题”(其方程由 Gnuplot 计算)只是“f(x)”。但是,我希望标题是回归线的方程,例如“y=mx+c”。

我可以通过从绘图信息输出中读取“m”和“c”来手动执行此操作,然后使用新标题重新绘图。我希望这个过程是自动化的,并且想知道这是否可以完成,以及如何去做。

【问题讨论】:

    标签: regression gnuplot


    【解决方案1】:

    来自Correlation coefficient on gnuplot

    另一种可能比 Woltan 做同样事情的方法略短的方法可能是:

    # This command will analyze your data and set STATS_* variables. See help stats
    stats Data.csv
    f(x) = STATS_slope * x + STATS_intercept
    plot f(x) title sprintf("y=%.2fx+%.2f", STATS_slope, STATS_intercept)
    

    【讨论】:

    • 只是一个fyi,stats命令无法在timedata mode, via the xdata时间设置时分析您的数据。 span>
    【解决方案2】:

    带有数据文件Data.csv

    0   0.00000
    1   1.00000
    2   1.41421
    3   1.73205
    4   2.00000
    5   2.23607
    

    您可以使用以下方法进行线性拟合:

    f(x) = a*x + b
    
    fit f(x) 'Data.csv' u 1:2 via a, b
    

    您可以使用我认为在 gnuplot 中所谓的宏来设置您识别函数 f(x) 的图例中的标题

    title_f(a,b) = sprintf('f(x) = %.2fx + %.2f', a, b)
    

    现在为了使用回归函数f(x) 绘制数据,只需执行以下操作:

    plot "Data.csv" u 1:2 w l, f(x) t title_f(a,b)
    

    你应该得到这个情节:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      相关资源
      最近更新 更多