How can I plot a trendline in gnuplot?
Thanx
Robin
my data file is as follows (de first column is a timeline, de second
column are data)
1 051.53
2 081.78
3 065.08
4 071.25
5 070.32
6 068.46
7 071.50
8 074.83
9 102.15
10 100.00
11 111.04
12 091.48
13 081.53
14 084.06
15 097.36
16 092.46
17 093.41
18 104.75
19 096.13
20 088.30
21 088.30
22 087.09
23 092.36
24 098.45
25 138.13
26 070.32
27 083.84
28 078.77
> How can I plot a trendline in gnuplot?
You can plot it just like any other data.
But that doesn't necessarily mean gnuplot will be able to _compute_ it
for you.
set terminal x11
set size 1.5,1.5
set yrange[0:5000] writeback
set xrange[0:29] writeback
set terminal png small xdfe0ff x1a1b48 xffffff x28b175
set output 'foo.png'
set xtics ("1621" 1, "1622" 2, "1623" 3, "1624" 4, "1625" 5, "1626" 6,
"1627" 7, "1628" 8, "1629" 9, "1630" 10, "1631" 11, "1632" 12, "1633"
13, "1634" 14, "1635" 15, "1636" 16, "1637" 17, "1638" 18, "1639" 19,
"1640" 20, "1641" 21, "1642" 22, "1643" 23, "1644" 24, "1645" 25, "1646"
26, "1647" 27, "1648" 28)
set ytics 0,250,5000
set grid
set key off
set xlabel "year" 3,-0.2
set ylabel "data" 0, 3
set title "title" 5,0
set style fill solid border -1
set style data points
set rmargin 4
set lmargin -5
set bmargin 4
set tmargin 5
set key autotitle
y(x) = m*x+c
fit y(x) 'foo.dat' using 1:2 via m, c
plot 'foo.dat' using 1:2 with linespoints pointtype 5 title "title"
plot y(x) title "line fit"
The result shows my data with linespoints in the graphics but I should
get a trendline in addition but it doesn't appear in the compiled png.
Maybe there is something missing but I don't know what.
Robin
This is the problem, here. If you have to specify two plots, use
multiplot. But in this particular case, you can manage it in just one
plot command, like this
> plot 'foo.dat' using 1:2 with linespoints pointtype 5 title "title", y(x) title "line fit"
This should work.
Cheers,
Zoltán
Thank you
Robin