根据特定调色板在 Gnuplot 中改变填充颜色

Varying filling colour in Gnuplot according to certain palette

我想使用 Gnuplot 填充多条闭合曲线。这是我目前得到的结果。

不错。我用过这个代码:

plot \
'fort.40' u 1:2 smooth bezier w filledcurves lt 1 lc 4 lw 3 t 't=100 s' ,\
'fort.30' u 1:2 smooth bezier w filledcurves lt 1 lc 3 lw 3 t 't=20 s' ,\
'fort.20' u 1:2 smooth bezier w filledcurves lt 1 lc 2 lw 3 t 't=1 s' ,\
'fort.10' u 1:2 smooth bezier w filledcurves lt 1 lc 1 lw 3 t 't=0'

然而,我真正想要的是绘制大约一百条这样的曲线(对于物理学家,我想要的是说明圆在相位 space 中的时间演化,例如双摆).每条闭合曲线存储为两列,曲线坐标存储在不同的 ASCII 文件中。如您所见,我已经通过手动设置四种不同的填充颜色实现了上图。但现在我想将其概括为根据特定的调色板实现颜色的平滑过渡。这个想法是颜色暗示了图中隐含的第三个维度:时间。

您知道是否可以使用遵循特定调色板的填充颜色而不是固定颜色吗?在最坏的情况下,我可以定义 100 种填充样式(我在 shell 脚本中创建代码,因此自动化该过程相对容易),但我仍然不知道是否可以分配颜色基于调色板,而不是手动给定颜色。

编辑:感谢@Christoph 的出色回答,这是最终输出。我把它留在这里只是为了说明 Gnuplot 有多强大。

filledcurves 绘图样式不支持 lc palettelc [rgb] variable,这是人们用来为线条着色的方式。

对于 filledcurves,您可以使用 lc palette frac <value>,其中 <value>[0:1] 范围内的数字,指定当前调色板中的小数位置,其中颜色取自。这需要你知道你正在绘制的文件数量:

set style fill solid noborder
plot \
'fort.40' u 1:2 smooth bezier w filledcurves lc palette frac 1 t 't=100 s' ,\
'fort.30' u 1:2 smooth bezier w filledcurves lc palette frac 0.6667 t 't=20 s' ,\
'fort.20' u 1:2 smooth bezier w filledcurves lc palette frac 0.3333 t 't=1 s' ,\
'fort.10' u 1:2 smooth bezier w filledcurves lc palette frac 0 t 't=0'

要遍历您可以使用的文件

files = 'fort.40 fort.30 fort.20 fort.10'
times = '100     20      1       0'
N = words(files)

set style fill solid noborder
plot for [i=1:words(files)] word(files, i) u 1:2 smooth bezier with filledcurves lc palette frac (N-i)/(N-1.0) t sprintf('t=%s s', word(times, i)