Gnuplot 不同颜色

标签 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. fit 命令与 plot 命令略有不同。您必须定义一个类似 f(x) = a*x + b 的函数,并将其适合您的数据。这将计算 ab 的适当值。然后您可以绘制函数的图像。

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

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

因此您的脚本应如下所示:

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

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

关于Gnuplot 不同颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19344210/

相关文章:

label - Gnuplot:用图像绘制时不显示标签

linux - 使用 Gnuplot 损坏的 Eps 图像/绘图

ruby - 如何使用 Gnuplot 创建多页 PDF 文件?

colors - 如何在 Gnuplot 中使关键颜色变黑

plot - 在 Maxima 中显示 3D 函数的有组织的自上而下 View

关闭窗口时退出 Gnuplot

gnuplot - gnuplot中的加号/减号?

Gnuplot 标题 - 使用 sprintf 在标题中使用变量

graph - gnuplot 改变连接线的颜色

Gnuplot:当日期序列中缺少数据时如何默认为 '0'