使用gnuplot确定二次方程的系数

时间:2013-10-17 19:04:57

标签: gnuplot

我已经根据stackoverflow上的输入创建了我的第一个图。所以我的代码是,

set title "Approximation Graph"
set term png
set output 'plot.png'
f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via 'clk0_h_c'
f1_h(x) = a1_h * x**2 + b1_h * x + c1_h
fit f1_h(x) 'clk1_h' via 'clk1_h_c'
f0_s(x) = a0_s * x**2 + b0_s * x + c0_s
fit f0_s(x) 'clk0_s' via 'clk0_s_c'
f1_s(x) = a1_s * x**2 + b1_s * x + c1_s
fit f1_s(x) 'clk1_s' via 'clk1_s_c'

set style data lines
plot "clk0_h" using 1:2, f0_h(x), "clk1_h" using 1:2, f1_h(x), "clk0_s" using 1:2, f0_s(x), "clk1_s" using 1:2, f1_s(x)

图表是:

enter image description here

所以我有一个小问题。

  

重要:是否可以使用gnuplot确定系数。作为   现在,我手动确定。 (某种原因,我不能在python中使用numpy   确定系数)

     

轻微:任何人都可以推荐我的行属性。 1)增加线宽   2)改变颜色3)为每一行添加标题(如果它们具有相同的则区分)   颜色)4)像我应该有8行,但有些是覆盖

1 个答案:

答案 0 :(得分:1)

关于你的第一个问题:fit实际上是这样做的。在您的脚本中,通过使用via 'file.par',您只需设置起始值并指定用于拟合的变量。

试试以下内容:

f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via a0_h, b0_h, c0_h

并且看看,如果系数很好。默认情况下,假设起始值为1。如果不能解决问题,您可能需要设置正确的数量级(在安装前设置为a0_h = 10)。

关于次要内容,请使用linewidthlinecolor等作为行属性。要指定标题,请使用title :)

您可以为每个函数/数据组合定义linestyle,并使用该行进行拟合,并指向数据:

set style line 1 linecolor rgb 'red' linewidth 2 pointtype 4 linetype -1
set style line 2 linecolor rgb '#ff7700' pointtype 7 linetype 2
...

在这种情况下,如果您指定linecolorlinetype,则第一个确定颜色,第二个确定短划线模式(终端支持它,请参阅Gnuplot line types)。< / p>

对于绘图,使用上述类型的线型定义,使用例如

set style data points
set style func lines # these two settings are default

plot "clk0_h" using 1:2 linestyle 1 title 'clk0_h, data', \
     f0_h(x) linestyle 1 title 'clk0_h, fit'
...

你应该考虑使用pngcairo终端,这会创建更好的图形。或者,最好使用基于矢量的终端,如pdfcairo