Gnuplot不同的颜色

时间:2013-10-13 10:37:32

标签: gnuplot

我正试图用不同的颜色为gnuplot上的情节和颜色着色,但它不起作用:

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

有人知道我做错了吗?

1 个答案:

答案 0 :(得分:2)

你做错了几件事:

  1. fit命令与plot命令略有不同。您必须定义类似f(x) = a*x + b的函数,并将其与您的数据相匹配。这会计算ab的适当值。然后你可以绘制函数。

  2. 您必须使用e终止内嵌数据。

  3. 要选择线条样式,请使用ls 1(数字前面的空格)。

  4. 所以你的脚本应如下所示:

    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
    

    将您的拟合绘制为一条线,将相应的数据绘制为点。