【问题标题】:Awk not working in the second part or sub plot of the gnuplot commandawk 在 gnuplot 命令的第二部分或子图中不起作用
【发布时间】:2020-08-14 22:28:11
【问题描述】:

通过 gnuplot,我试图在图表上打印一条平均线,但如果我在第二部分中使用 awk 命令或像这样的第二个子图命令,它不起作用

plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
     "<awk '{sum += $2} END {print sum/NR}' iops.1.log" with lines title "avg iops"

但是,如果我直接给出我在 bash 命令行上运行相同的 awk 命令时得到的值,则该行会像这样打印。

plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
     4590 with lines title "avg iops"

上面的行仅使用第二个子图中的一个值(4590)打印图表中的运行平均线

究竟发生了什么,为什么一定不能正常工作?

【问题讨论】:

    标签: awk gnuplot average


    【解决方案1】:

    这可能是一个错误,但幸运的是,您可以在不需要 awk 的情况下计算 gnuplot 中的平均 y 值:

    stats "iops.1.log" nooutput
    ave=STATS_sum_y/STATS_records
    plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
     ave with lines title "avg iops"
    

    【讨论】:

      【解决方案2】:

      当使用plot "&lt;awk ..." 绘图并且awk-命令返回单个数字时,您实际上拥有一个带有单个数字的数据文件。 与此相反,调用 plot 4560 会绘制一个 函数,然后在整个 x 范围内绘制该函数。

      如果你想坚持使用awk,或者只是作为替代方案的解释,你可以这样做

      avg = system("<awk '{sum += $2} END {print sum/NR}' iops.1.log")
      plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
           int(avg) with lines title "avg iops"
      

      【讨论】:

        【解决方案3】:

        "&lt;..." 构造提供了一个管道文件。要计算和绘制平均值,您可以使用 背部抽动:

        plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
            `awk '{sum += $2} END {print sum/NR}' iops.1.log` with lines title "avg iops"
        

        【讨论】:

          猜你喜欢
          • 2016-03-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-08-22
          • 1970-01-01
          • 2021-10-17
          相关资源
          最近更新 更多