【问题标题】:How can I include details from the directory name in a gnuplot title?如何在 gnuplot 标题中包含目录名称的详细信息?
【发布时间】:2014-09-01 18:26:43
【问题描述】:

如何在我的 gnuplot 标题中包含目录名称的详细信息?目前,我的 gnuplot 脚本是:

set multiplot title "Pressure Convergence Plots"

但我想让标题说:“溢出率 1 和网格细化 0 的压力收敛图”,其中“Q1_GR0”是目录名称,“1”和“0”是“Q”后面的数字'和目录名称中的'GR'。

如果这不可能,标题是否可以说:“Q1_GR0 的压力收敛图”,其中“Q1_GR0”是目录名称?

我正在使用 gnuplot 4.6 版

谢谢。

【问题讨论】:

    标签: bash gnuplot


    【解决方案1】:

    这取决于您拥有的 sed 版本,但这对我有用:

    rep = sprintf("Pressure Convergence Plots for overflow rate \\1 and grid refinement \\2")
    t = system(sprintf("sed -r 's/SF[0-9]+_Q([0-9]+)_GR([0-9]+)/%s/' <<<${PWD##*/}", rep))
    set multiplot title t
    

    sed 命令从 Q 和 GR 之后捕获数字并将它们用于替换字符串。我使用sprintf 将命令分成两行。

    【讨论】:

    • 完整的目录名称是 'SF1_Q1_GR0'。我不认为“SF1”会干扰答案,但是使用您的脚本,标题是:“SF1_Pressure Convergence Plots for overflow rate 1 and grid refinement 0”。如何从标题中删除“SF1_”?谢谢。
    • 我已经编辑了正则表达式。它现在应该做你想做的事了。
    • 或者您可以使用sed -r 's/.*Q([0-9]+)_GR([0-9]+)/%s/'跳过所需令牌之前的所有内容。
    • @Christoph 或者您甚至可以使用 &lt;&lt;&lt;${PWD##*_Q} 之类的内容从输入中删除更多路径。可能性是无止境! :)
    • 是的,这确实是无穷无尽的。我刚刚提到了.*,因为在我看来最好让它保持通用,所以这也适用于目录RR15_Q1_GR2。如果需要那是另一回事;)
    【解决方案2】:

    这可以通过 bash 命令完成。我喜欢它很复杂:

    rate = "`pwd | rev | cut -f 1 -d '/' | rev | cut -f 2 -d 'Q' | cut -f 1 -d '_'`"
    refinement = "`pwd | rev | cut -f 1 -d '/' | rev | cut -f 2 -d 'R'`"
    fulltitle = 'Pressure Convergence Plots for overflow rate '.rate.' and grid refinement '.refinement
    set multiplot title fulltitle
    

    【讨论】:

    • 另一个变种可能是:info = system('pwd | sed ''s:.*/Q\([0-9]*\)_GR\([0-9]*\)$:\1 \2:'' '); set multiplot title 'Rate '.word(info, 1).' refinement '.word(info, 2)
    猜你喜欢
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 2021-01-20
    相关资源
    最近更新 更多