如何用y改变拟合函数的线条颜色? [英] How can I make the line color of a fitted function change with y?
问题描述
因此,如果我有一组数据,请说"GnuTest.dat",然后对它拟合f(x)= a * x ** 2,然后将它们都绘制出来,有没有办法使f的颜色(x)是否随f(x)不同?
So if I have a set of data, say "GnuTest.dat" and I fit f(x) = a*x**2 to it, then plot them both, is there a way to have the color of f(x) vary with 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)值之间改变颜色.我尝试将:(f(x)/STATS_max_y)
或类似的内容放在using 1:2
之后,但是我总是会收到类似"x notdefined"或; Expected"之类的错误.我缺少明显的东西吗?
So in theory, I would like to vary the color along the hue scale between the minimum and maximum f(x) values. I've tried putting :(f(x)/STATS_max_y)
or something similar after using 1:2
, but I always get errors like "x not defined" or "; expected". Am I missing something obvious?
编辑:这是我的情节遵循@Christoph的建议的样子.我有set termoption solid
并使用了lt -1
.
This is how my plot looks following @Christoph's advice. I have set termoption solid
and used lt -1
.
推荐答案
要在函数中使用可变线色,必须使用'+'
特殊文件名.这样,您就可以使用using
选项,该选项对于可变linecolor来说是必需的.请注意,这根本与拟合无关.
In order to use a variable linecolor with a function, you must use the '+'
special filename. That allows you to use the using
option, which is required for use with variable linecolor. Note, that this is not related at all to fitting.
这是一个最小的可运行脚本:
Here is a minimal, runnable script:
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的结果是:
The result with 4.6.3 is:
请注意,您不能使用maxcolors 1
,因为这(至少对我来说)仅是黑色.
Note, that you cannot use maxcolors 1
, as this gives (at least for me) only black.
这篇关于如何用y改变拟合函数的线条颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!