【问题标题】:Varying filling colour in Gnuplot according to certain palette根据某些调色板在 Gnuplot 中改变填充颜色
【发布时间】:2015-07-02 07:59:24
【问题描述】:

我想使用 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'

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

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

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

【问题讨论】:

    标签: gnuplot fill


    【解决方案1】:

    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)
    

    【讨论】:

    • 不仅是一个非常精确的答案,而且我可以学到一些新东西,而且你的回答比我写问题的速度还要快。在将其标记为已回答之前,我会尝试一下,但我很确定它会起作用。谢谢。
    • 出于好奇,我编辑了问题以添加最终输出。我希望这不违反网络规则。非常整洁,虽然阴影有我想移除的丑陋伪影。但我想这是另一个问题的主题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    相关资源
    最近更新 更多