【问题标题】:How can I make the line color of a fitted function change with y?如何使拟合函数的线条颜色随 y 变化?
【发布时间】:2014-03-07 16:49:23
【问题描述】:

所以如果我有一组数据,说“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) 值之间沿色调比例改变颜色。我试过在using 1:2 后面加上:(f(x)/STATS_max_y) 或类似的东西,但我总是收到诸如“x 未定义”或“;预期”之类的错误。我错过了什么明显的东西吗?

编辑:这是我遵循@Christoph 建议的情节。我有set termoption solid 并使用过lt -1

【问题讨论】:

标签: gnuplot


【解决方案1】:

为了在函数中使用变量 linecolor,您必须使用 '+' 特殊文件名。这允许您使用using 选项,这是与可变线条颜色一起使用所必需的。请注意,这与拟合完全无关。

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

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 的结果是:

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

【讨论】:

  • 谢谢,解决了我问题的主要部分(因此被接受)。然而,在我的终端(aquaterm)中,无论我对linetype 做了多少摆弄,我都只能得到一条虚线。 maxcolors 应该是 0,这只是我在尝试找到自己的解决方案时玩弄的事情之一!
  • 我从未使用过 aquaterm,所以这是一种猜测。您应该只能使用带有set termoption solid 的实线。此外,线型 -1 应该始终是实心的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
相关资源
最近更新 更多