3
votes

I'm attempting to try some simple regression lines as the basis of a gnuplot graph. However, no matter what I do, I can't get more than one fit line on a graph. Is this even possible? Here's my (current) gnuplot program....

set title "Foo" font "Arial Bold,14"
set term epscairo size 8,5
set style line 1 lw 0 pt 7 lc rgb "black"
set key outside
set pointsize .75
set ylabel "Y Range" font "Arial Bold"
set xlabel "X Range" font "Arial Bold"
set grid ytics
set yrange [-1:100]
set xrange [1:80]
set output 'graph.ps'

f1(x) = a1*x + b1
fit f1(x) "data/dvdate/1" using 2:3 via a1,b1

f2(x) = a1*x + b1
fit f2(x) "data/dvdate/2" using 2:3 via a1,b1

f3(x) = a1*x + b1
fit f3(x) "data/dvdate/3" using 2:3 via a1,b1

plot f1(x) title '# 1', f2(x) title '# 2', f3(x) title '# 3'

The result is that I have get one .ps file with one line it (not overlaying other lines) with the three data series labels.

2

2 Answers

4
votes

you need to use different variables (a1,b1) in each fit.

f2(x) = a2*x + b2
fit f2(x) "data/dvdate/2" using 2:3 via a2,b2
0
votes

You can call external program within gnuplot using '!' and a loop will generate a temporary file to load right after.

!rm filetoload
! for ((i=1;i<=50;i++)); do echo "f$i(x)=a$i*x+b$i; fit f$i(x) './file$i' u 1:2 via a$i, b$i">> filetoload;done
!cat filetoload
load "filetoload"

will generate:

f1(x)=a1*x+b1; fit f1(x) file1 u 1:2 via a1, b1
f2(x)=a2*x+b2; fit f2(x) file2 u 1:2 via a2, b2
f3(x)=a3*x+b3; fit f3(x) file3 u 1:2 via a3, b3
...

adapt as wishes