如何使拟合函数的线条颜色随y变化?

时间:2014-03-07 16:49:24

标签: gnuplot

所以,如果我有一组数据,说“GnuTest.dat”,我将f(x)= a * x ** 2拟合到它,然后将它们绘制成两者,是否有办法获得f的颜色(x)随f(x)变化?

这就是我现在所拥有的:

set autoscale
set term aqua size 700,500
set palette positive nops_allcF maxcolors 1 gamma 1.5 color model HSV
set palette defined ( 0 0 1 1 , 1 1 1 1 )
unset log
set termoption enhanced
set xtics 1
set mxtics 4
set ytics 1
set mytics 4
set title "Gnuplot Script Template"
set xlabel "x"
set ylabel "y"
set size ratio -1
a = 1
b=0.5
f(x) = a*x**2 +b
stats "GnuTest.rtf" u 1:2
print STATS_max_y;
fit f(x) "GnuTest.rtf" using 1:2 via a,b
plot "GnuTest.rtf" using 1:2 title "Gnu Test" w points pt 7, f(x) t "ax^2 + b fit" w lines lc variable

所以理论上,我想在最小和最大f(x)值之间沿着色调比例改变颜色。我已尝试在:(f(x)/STATS_max_y)之后添加using 1:2或类似内容,但我总是会遇到“x not defined”或“; expected”等错误。我错过了一些明显的东西吗?

编辑:这就是我的情节看起来跟随@Christoph的建议。我有set termoption solid并使用lt -1

GnuScriptTemplate

1 个答案:

答案 0 :(得分:3)

要将变量linecolor与函数一起使用,必须使用'+'特殊文件名。这允许您使用using选项,这是与变量linecolor一起使用所必需的。请注意,这与拟合无关。

这是一个最小的,可运行的脚本:

set palette defined ( 0 0 1 1 , 1 1 1 1 ) color model HSV gamma 1.5
set xrange[0:10]
f(x) = x**2
plot '+' using 1:(f($1)):(f($1)) with lines linecolor palette lw 3 notitle

4.6.3的结果是:

enter image description here

请注意,您无法使用maxcolors 1,因为这会给(至少对我而言)只有黑色。

相关问题