【问题标题】:gnuplot: Use only last n linegnuplot:仅使用最后 n 行
【发布时间】:2014-05-10 22:48:11
【问题描述】:

我正在使用 python 脚本将来自两个温度传感器的数据记录到 .csv 文件中。每次读取(每 5 分钟)都会在文件末尾添加一个新行。我怎样才能让 gnuplot 只使用最后 288 行,所以我最终会得到最后 24 小时的图表?

谢谢!

:编辑:

知道了,感谢@Istvan Chung 的提示。

一个简单的

plot '< tail -n 288 datafile.csv' using ...

似乎可以解决问题。

【问题讨论】:

  • 我没用过gnuplot,但是类似tail -n 288 &lt;file&gt; | gnuplot -p -e "set datafile separator \",\"; plot '-'"的东西?
  • 很高兴看到您解决了这个问题;通常最好将您的(完整)解决方案作为答案发布,以便人们可以看到它已得到解决。
  • @IstvanChung 也许你可以回答这个问题并在这个过程中获得一些代表点,因为你还是建议了解决方案。

标签: csv gnuplot


【解决方案1】:

这里一个简单的解决方案是使用 unix tail 命令选择最后 288 行。

我在评论中建议

tail -n 288 <file> | gnuplot -p -e "set datafile separator \",\"; plot '-'"

应该可以。根据对原始问题的编辑,这里的正确语法格式为

plot '< tail -n 288 datafile.csv' using ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多