【问题标题】:loops in gnuplot inside the plot command绘图命令内的gnuplot中的循环
【发布时间】:2014-10-12 09:45:46
【问题描述】:

我在 plot 命令内的 gnuplot 中使用 for 循环时遇到问题。这是一个精简的 gnuplot 脚本,它专注于不工作的部分:

set multiplot layout 1, 3 title "Convergence Plots"
planeIter=4

do for [ringIter=0:20:10] {
    if (ringIter == 0) {ringName="outer"} else {if (ringIter == 10) {ringName="middle"} else {ringName="inner"}}
    set title "Pressure in ".ringName." ring"
    plot for [quadIter=0:90:30] path1 every ::5 using 1:(1 + planeIter + ringIter + quadIter) notitle   # title quadName.' quadrant' with lines
#   if (quadIter == 0) {quadName="first"} else {if (quadIter == 30) {quadName="second"} else {if (quadIter == 60) {quadName="third"} else {quadName="fourth"}}}
}

我的问题是:

  1. 我在哪里/如何包含(注释掉的)if/else 语句,以便我可以用 # 符号后面的“标题”替换上面行中的“notitle”?
  2. 绘制的线应该是 p 中的以下列:(1:5, 1:35, 1:65, 1:95), (1:15, 1:45, 1:75, 1:105)和 (1:25, 1:55, 1:85, 1:115) 但不是取第二列 (5, 35, 65, ...) 中的值,而是绘制列号(即常数)。如何让 plot 命令选择列内的值?

我已经包含了它的外观和应该是什么样子的图像(下),这是我通过不使用 for 循环和 quadName 的变量生成的。

文件 p 是一个数字列表,每行包含 121 列。

感谢您提供的任何帮助。

【问题讨论】:

    标签: variables for-loop gnuplot


    【解决方案1】:

    要使用变量来指定选定的列,您必须使用column(var),即在您的情况下为using 1:(column(1 + planeIter + ringIter + quadIter))

    要为标题选择一个单词,您可以定义一个返回相应字符串的函数,例如:

    quadName(x) = (x == 0 ? "first" : (x == 30 ? "second" : (x == 60 ? "third" : "fourth")))
    plot for [quadIter=0:90:30] path1 using 1:(column(1 + planeIter + ringIter + quadIter)) \
        title quadName(quadIter).' quadrant' with lines
    

    或者,您也可以使用word 函数,这对于更多选择可能会更好:

    quadName = "first second third fourth"
    plot for [quadIter=0:90:30] path1 using 1:(column(1 + planeIter + ringIter + quadIter)) \
        title word(quadName, (quadIter / 30) + 1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多