【问题标题】:Gnuplot: skip last/incomplete line of data fileGnuplot:跳过数据文件的最后/不完整行
【发布时间】:2015-08-12 21:33:40
【问题描述】:

我有一个使用嵌入式 lua 脚本将数据点从程序写入文件的 C++ 程序,我希望同时能够运行 gnuplot 实例来绘制数据点。

io.output(pfile);
io.write(t, "\t", p_x, "\t", p_y, "\t", p_z, "\n");

gnuplot 文件如下所示:

set termopt enhanced

set title "Linear Momentum Vector"
set xlabel "t (s)"
set ylabel "p (N-s)"

plot "data/plot_p.dat" using 1:2 title "p_x(t)" with lines, \
     "data/plot_p.dat" using 1:3 title "p_y(t)" with lines, \
     "data/plot_p.dat" using 1:4 title "p_z(t)" with lines

set style line 81 lt 0 lc rgb "#808080" lw 0.5

set grid xtics ytics mxtics mytics
set grid back ls 81

pause 0.25
reread

上面的 gnuplot 脚本适用于完整的数据文件,但我希望它在程序运行时实时绘制。当 lua 脚本写入文件时,有时 gnuplot 脚本会捕获最后一行不完整的文件。这会产生一个错误:

"liveplot_p.gnu", line 9: x range is invalid

如何让 gnuplot 为最后一行或无效数据集编写脚本?

谢谢!

【问题讨论】:

    标签: c++ plot lua gnuplot real-time


    【解决方案1】:

    一些与 lua 相关的问题实际上为我解决了这个问题。在 io.write(...) 调用之后调用 io.flush() 函数似乎每次都将完整的行写入文件。

    这当然不会告诉 gnuplot 跳过或忽略最后一行,但它确保最后一行是完整的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-21
      • 2019-01-15
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多