Gnuplot不同的颜色 [英] Gnuplot different colors
问题描述
我正在尝试用不同的颜色为绘图和gnuplot中的拟合着色,但这是行不通的:
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?
推荐答案
您做错了几件事:
-
fit
命令与plot
命令有点不同.您必须定义一个像f(x)= a * x + b
的函数,并将其适合您的数据.这将为a
和b
计算适当的值.然后,您可以绘制函数.
The
fit
command is a bit different from theplot
command. You must define a function likef(x) = a*x + b
and fit this to your data. This calculates appropriate values fora
andb
. Afterwards you can plot the function.
您必须使用 e
终止内联数据.
You must terminate the inline data with an e
.
要选择线条样式,请使用 ls 1
(在数字前带有空格).
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.
这篇关于Gnuplot不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!