Gnuplot - 根据 x 值对图进行着色

pel*_*egs 5 gnuplot colors

我想根据函数图的 x 值更改图的颜色(即不是来自数据文件)。
例如,我定义一个调色板如下:
set palette defined ( 0 'purple', 1 'blue', 2 'green', 3 'yellow', 4 'orange', 5 'red' )
我希望sin(x)根据 [0:5] 范围内的 x 值使用我的调色板函数来使用颜色。
如何才能做到这一点?

use*_*153 5

您可以用于linecolor palette此目的,这需要指定包含颜色信息的附加列。对于函数图,您可以使用特殊的文件名'+'来获得命令的全部多功能性using

set palette defined ( 0 'purple', 1 'blue', 2 'green', 3 'yellow', 4 'orange', 5 'red' )
set xrange [0:5]
plot '+' using 1:(sin($1)):1 with lines linewidth 3 linecolor palette
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述