【问题标题】:how to plot power trendline showing equation and regression coefficient (like in the image below) in gnuplot?如何在 gnuplot 中绘制显示方程和回归系数的功率趋势线(如下图所示)?
【发布时间】:2015-06-17 07:30:15
【问题描述】:

我正在尝试重新创建我使用 gnuplot 在 MS Excel 中创建的绘图。这可以在显示具有相应回归系数的功率趋势线方程的 gnuplot 中完成吗? 必须绘制的数据来自文件:“data.txt”,“x”的数据来自第 10 列,“y”的数据来自第 11 列。 谢谢!

【问题讨论】:

    标签: plot gnuplot trendline


    【解决方案1】:

    我设法制作了上述 excel 图的工作版本。然而,任何改进都受到高度赞赏。 谢谢。 我在 gnuplot 中的代码是

          set terminal svg enhanced fname "Times-New-Roman,12"
          set xlabel "x"
          set ylabel "y"
          set xrange [0:*]
          set yrange [0:*] 
          set format x "%0.3f" 
          set format y '%0.3f'
          set title sprintf("y=f(x)")
    
          # plot
          filename="data.txt"
          plotfile="out.svg"
          set output plotfile
          f(x)=a*x**b
          fit f(x) filename using 10:11 via a,b
          set label GPFUN_f at graph .15,.95
          set label sprintf("a = %g",a) at graph .15,.90
          set label sprintf("b = %g",b) at graph .15,.85
          plot filename using 10:11 title "y(x)" with points pointtype 1 pointsize 1,\
      f(x) title "power-trendline" with line linewidth 2
    

    ![power-trendline-gnuplot]

    【讨论】:

    • 为什么不使用这样的“增强”可能性:set label sprintf("y(x)=%f.x^{%f}",a,b) at graph .15,.95 而不是set label GPFUN_f at graph .15,.95
    • 您甚至可以像这样控制重要数字的数量:set label sprintf("y(x)=%.4f.x^{%.3f}",a,b)
    • @Heisenberg 谢谢,这改进了图表,如何像上图中的那样将 R^2 值添加到图表中?
    • 嘿,您的图片已损坏 - 可能需要使用此处的“上传”功能将其存储在我们自己的图片主机上,这样就不会发生这种情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多