3

I have these data :

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

And the gnuplot script :

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

I would like to put a trendline like that :

enter image description here

But I'm very bad in math and I don't know how to do that with gnuplot... Someone to show me ?

B--rian
  • 5,578
  • 10
  • 38
  • 89
Makmy
  • 187
  • 1
  • 12

1 Answers1

4

Supposing your data as described by a straight line, you can use define such equation and use the fit command.

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"

Result

fit

grsousajunior
  • 743
  • 1
  • 6
  • 12
  • Hello, thank you for you answer ! Very helpful ! I understand how to do that with one curve but If I have these date ( https://pastebin.com/K9e3Aa57 ) with this gnuplot script ( https://pastebin.com/0XEJvz6V ), I create two curves, one for the free space, and an other for the total capacity in mb... How I can create a trendline for the first and the second curve ? – Makmy Sep 09 '19 at 09:40
  • You could define two straight line equation and perform two fit or save the parameters to another variables after each fit command instead. However, the `total capacity` data are constant. The `free space` data are discontinuous. So, for this last one, a straight line is not a best model to data fit. – grsousajunior Sep 09 '19 at 11:46