【发布时间】: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