Search code examples
plotgnuplottrendline

how to plot power trendline showing equation and regression coefficient (like in the image below) in gnuplot?


I am trying to recreate the plot that I created in MS Excel using gnuplot. Can this be done in gnuplot which shows the power trendline Equation with corresponding Regression Coefficient? The data has to be plotted is from file:'data.txt' and the data for 'x' is from column 10 and for 'y' from column 11. Thanks!

power trendline


Solution

  • I managed to produce a working version of above excel figure. However any improvement is highly appreciated. Thanks. My code in gnuplot is

          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] enter image description here