ovmcit5eoivc4
ovmcit5eoivc4

Reputation: 163

Gnuplot different colors

I'm trying to color a plot and a fit in gnuplot in different colors, but it doesn't work:

set ylabel "s in m"
set xlabel "t in s"
unset key
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "orange" lw 2
plot "-" with lines ls1
0 0
1 4.2
2 7.9
3 11.7
4 16.3
fit "-" with lines ls2
0 0
1 4.2
2 7.9
3 11.7
4 16.3

Does anybody have an idea what I am doing wrong?

Upvotes: 2

Views: 3005

Answers (1)

Christoph
Christoph

Reputation: 48390

There are several things you are doing wrong:

  1. The fit command is a bit different from the plot command. You must define a function like f(x) = a*x + b and fit this to your data. This calculates appropriate values for a and b. Afterwards you can plot the function.

  2. You must terminate the inline data with an e.

  3. To select a line style, use ls 1 (with the space before the number).

So your script should look as follows:

set ylabel "s in m"
set xlabel "t in s"
unset key
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "orange" lw 2

f(x) = a*x + b
fit f(x) '-' via a,b
0 0
1 4.2
2 7.9
3 11.7
4 16.3
e

plot f(x) with lines ls 2, "-" with points ls 1
0 0
1 4.2
2 7.9
3 11.7
4 16.3
e

This plots your fit as a line, and the according data as points.

Upvotes: 2

Related Questions